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 CompilerInterpreter
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 InterpreterCompiler and Interpreter compared
| Aspect | Compiler | Interpreter |
|---|---|---|
| When translation happens | Before the program runs, in a separate build step | While the program runs, statement by statement |
| Output | An executable file or bytecode | No separate file; the program runs directly |
| Execution speed | Usually faster; code is optimized ahead of time | Usually slower, unless a JIT compiler helps |
| Error reporting | Many errors reported before the program runs | Errors surface when the faulty line is reached |
| Feedback loop | Edit, compile, then run | Edit and run at once, often in an interactive REPL |
| Portability | Binaries target a specific CPU and operating system | Source runs anywhere the interpreter is installed |
| Examples | Compilers for C, C++, Rust and Go | CPython, 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
# Compile first, producing a binary
gcc hello.c -o hello
# Then run the binary (no compiler needed now)
./hello# The interpreter reads and runs the source directly
python3 hello.py
# Or type code interactively in a REPL
python3Readers 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.