1

Firstly, I want you to check the best answer over here.

Compiled vs. Interpreted Languages

As you can see, it says, compiled languages are faster. However, what I know for granted is that compilers take the whole source code, compiles it to machine code, then executes it. Interpreter takes one statement at a time, translates it to machine code or virtual machine code, then executes it immediately. So we get the output on the fly, during the run-time.

Then aren't interpreted languages faster than compiled languages?

Community
  • 1
  • 1
Haggra
  • 3,539
  • 2
  • 20
  • 28
  • 2
    How does that conclusion follow from its premise? – harold May 02 '15 at 07:50
  • Compiling is a one time activity, which is not counted in execution time because you don't have to compile every time you run. – RaGe May 02 '15 at 07:50
  • A compiler doesn't execute code after compilation. It just generates the binary which can be executed again and again. – Mark Rotteveel May 02 '15 at 07:51
  • #RaGe #Mark Rotteveel For instance, if we were to run a Java application, will it interpret every single time the whole code? – Haggra May 02 '15 at 07:54
  • 1
    from bytecode, yes. look up "Just In Time" – RaGe May 02 '15 at 07:57
  • Yes, you're right, there are cases where direct ad hoc interpretation is much faster than compilation + execution. If your code will only run once and does not contain long loops interpreting it makes sense. This applies to command languages (shells and such), communication protocols, etc. – SK-logic May 05 '15 at 12:20

1 Answers1

7

You are trying to compare "Code Compiling" vs "Code Interpreting"

"Code Compiling" doesn't execute the code it only creates a binary or platform independent code which can be run over and over again with no need of re-compilation or minimal compilation which has much less overhead than interpreting like in Java

"Code Interpreting" - compiles the code line by line in memory and executes it on the fly

So compiled languages are faster in execution as at the time of execution no compilation is required but in interpreted languages each execution step is preceded by a compilation step every time, making it slow.

adnan kamili
  • 8,967
  • 7
  • 65
  • 125