Dynamically compiled language vs statically compiled language

14,423

Solution 1

Dynamic compiled and dynamically typed don't have much to do with each other. Typing is part of the language syntax, while the compilation strategy is part of the implementation of the language.

Dynamic typing means that you don't necessarily have to declare the type when you declare a variable and that conversion between types happens automatically in most cases.

Dynamic compiling means that the language is compiled to machine code while the program is being executed, not before. This allows, for example, just-in-time optimization - the code is optimized while the application is running. A JIT optimizer has the advantage that it has much more reliable information about which branches of the code are used most often and how they are usually used, because it can observe the application in action before applying optimizations.

Dynamic compilation is a problem for automatic benchmarking, because multiple measurements of the same program code section can compare completely different machine code interpretations because the optimizer has decided to change the implementation between two runs.

Solution 2

C and C++ source code are normally compiled to native machine code by a compiler.

Java is compiled to bytecode by the Java compiler. When you run your Java program, a just-in-time (JIT) compiler might compile the Java bytecode to native machine code for the CPU that the program is running on.

Compiling the program to native machine code when the programs runs is also called dynamic compilation.

Solution 3

Dynamic versus static compilation refers to how, and if, the compiler generated code can be changed during execution to change the performance or the program.

Static compilation allows no such manipulation since all addresses and jumps are fixed (unless you yourself write the code to change the instruction order during execution).

Dynamic compilation allows inspection during program execution and the gathered information can be used to make things run faster. The Wikipedia article is an easy read and pretty informative.

Solution 4

The difference, from the benchmark point of view, is that execution time of dynamically compiled program can change dramatically during the execution. Usually java code is being interpreted first, then, when interpreter discovers that some method are invoked many times, it calls JIT compiler to convert them to native code. The compiled code is still monitored and, when frequently executed parts of code ("hot spots") are determined, they are optimized further.

As a minimum, benchmarks for dynamically compiled languages must treat "warming phase" (when code is optimized) separately from the rest of the execution.

Share:
14,423
Geek
Author by

Geek

Updated on June 16, 2022

Comments

  • Geek
    Geek almost 2 years

    The first line of this article by Brian Goetz made me to post this question in SO . Here 's the line again:

    Writing and interpreting performance benchmarks for dynamically compiled languages, such as Java, is far more difficult than for statically compiled languages like C or C++.

    I know the answer of statically typed vs dynamically typed language . But what is the difference between dynamically compiled language vs statically compiled language?