Skip to main content

Side by side

CompilervsInterpreter

What is the difference between a compiler and an interpreter?

Updated 2 min read7 differences

In short

A compiler translates a whole program before it runs, while an interpreter executes source code step by step at runtime, trading raw speed for faster feedback.

Compiler

A compiler is a program that translates source code written in a programming language into a lower-level form, such as machine code, that a computer can run.

Read the page on Compiler

Interpreter

An interpreter is a program that runs source code directly, step by step, instead of first translating the whole program into a separate executable file.

Read the page on Interpreter

Compiler and Interpreter compared

AspectCompilerInterpreter
When translation happensBefore the program runs, in a separate build stepWhile the program runs, statement by statement
OutputAn executable file or bytecodeNo separate file; the program runs directly
Execution speedUsually faster; code is optimized ahead of timeUsually slower, unless a JIT compiler helps
Error reportingMany errors reported before the program runsErrors surface when the faulty line is reached
Feedback loopEdit, compile, then runEdit and run at once, often in an interactive REPL
PortabilityBinaries target a specific CPU and operating systemSource runs anywhere the interpreter is installed
ExamplesCompilers for C, C++, Rust and GoCPython, the Ruby interpreter and shells like Bash

The difference, explained

A compiler is a program that translates source code into another form, usually machine code or bytecode, ahead of time, producing output you run later. An interpreter executes source code directly, reading each statement, working out what it means and carrying it out while the program runs.

The trade-off is when the translation work happens. Compiling up front lets the compiler analyze and optimize the whole program and report many errors before anything runs, so compiled programs are usually faster. Interpreting skips the build step, so changes run immediately and the same source works anywhere the interpreter is installed.

Most modern language implementations blend both. Java and C# compile to bytecode that a virtual machine runs, Python compiles source to bytecode before interpreting it, and JavaScript engines start by interpreting code and then use a just-in-time (JIT) compiler to turn frequently run code into machine code.

A common misconception is that a language itself is compiled or interpreted. That is a property of the implementation: C is usually compiled but C interpreters exist, and Python can be run by its standard interpreter or by compiling tools.

Which one should you use?

Choose Compiler when…

  • Runtime performance is a top priority.
  • You want to ship a single standalone executable.
  • You want errors caught before the program ever runs.

Choose Interpreter when…

  • You want to try code instantly without a build step.
  • The same script must run unchanged on many platforms.
  • You are writing automation, glue code or quick experiments.

Running a program each way

Compilerbash
# Compile first, producing a binary
gcc hello.c -o hello

# Then run the binary (no compiler needed now)
./hello
Interpreterbash
# The interpreter reads and runs the source directly
python3 hello.py

# Or type code interactively in a REPL
python3

Readers ask

Is Python compiled or interpreted?

Both, in a sense. The standard implementation, CPython, compiles source code to bytecode and then interprets that bytecode, and recent versions add an experimental JIT compiler.

Is JavaScript compiled or interpreted?

Modern JavaScript engines do both. They start by interpreting code for fast startup and use a just-in-time compiler to turn frequently run code into optimized machine code.

What is a JIT compiler?

A just-in-time compiler translates code into machine code while the program is running, focusing on the parts that run most often, which combines quick startup with good long-run speed.

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings