Compiler vs Interpreter – Difference between compiler and interpreter

Compiler and interpreter both are tools to translate source code from high-level language to machine language. Both does the same task of translation. But the working mechanism of compiler is different from interpreter. Below are some differences between compilers and interpreters

Translation mechanism

Compiler reads entire source code and translates to machine language at once. If any error is generated during compilation, it terminates the entire process without executing single instruction.

Whereas interpreters translate instruction-by-instruction. It reads single instruction at a time. Translates it to machine language and executes it. This process continues till the last instruction. If any error is generated during the interpretation, it terminates the execution of further instructions.

Translation time

Compilers reads entire source code at once. It pre-processes, parses, analyses the source code and translates it to machine code at once. Hence, it requires more translation time than interpreters.

Interpreters reads single instruction of source code at a time. Unlike compilers, it doesn’t translate entire source code to machine code at once. Rather it translates the source code, instruction by instruction. Hence, requires less translation time.

Program speed

Compilers translate entire source code at once. After the compilation process, it generates an executable file containing complete instruction set of the program in binary language. Hence, it doesn’t require any further translation which enhances the program execution speed.

Interpreters translate the source code instruction by instruction. It translates single instruction then executes it. Each time before executing an instruction, it must first translate it to machine language. Which increases the overhead of interpretation, hence decreases the program execution speed.

Memory consumption

Compilers usually generate an intermediate code called object code, during the compilation process. Hence it requires more memory than interpreters.

Unlike compilers, interpreters do not generate any intermediate code, during the interpretation process. Thus, interpreters are memory efficient.

Debugging

Compilers continues to process entire source code also if it contains errors. It generates list of all error messages (if any) at the end of the compilation process. Which makes debugging a little difficult.

Interpreters stops the interpretation process if an error is encountered. It generates the error message as the error is met during the interpretation process.

Deployment

Compilers generate an executable file of the source code. This executable file is deployed instead of source code. Which increases the security, by hiding the source code from others.

Interpreters do not generate any executable file of the source code. Therefore, in the case of interpreter’s entire source code needs to be deployed. Causing a security concern as the source code is visible to everyone.

Compiler vs Interpreter

Summing up the differences between compiler and interpreter.

CompilerInterpreter
It translates entire program to machine code at once.It translates single instruction of a program at a time.
It requires more translation time.It requires less translation time.
Program execution is faster than interpreted languages.Program execution is slower than compiled languages.
It usually generates additional intermediate code.It doesn’t generate additional intermediate code.
It requires more memory as it generates extra object code.It requires less memory as it does not generate any intermediate code.
Errors are displayed at the end of the compilation process.Errors are displayed as they met.
Executable code needs to be deployed.Source code needs to be deployed.
Example of compiled languages – C, C++, Java etc.Example of interpreted languages – Ruby, Python, Shell script etc.