What is the difference between runtime and compile-time?

Share

A software program is a set of understandable computer commands that instructs the computing system to carry out a task or set of tasks.

Digital computers only understand 1s and 0s. So, the question is: how do they understand if, else, while, do, and other jargon that is in our code?

How digital computers understand our code jargon

Our computing devices only understand machine codeSets of ones and zeros called digital signals that are written in machine language that represent instruction sets executable by the system.. However, our programs are written in high-level languages such as PHP, Python, Java, C, C++, etc. The bridge that is created between our high-level program and the machine code depends on the following processes:

  1. Interpretation
  2. Compilation
  3. Assembling

Interpretation

Interpretation is a process in which high-level program codes are translated into machine codes with the use of an interpreter. An interpreter translates the program codes line by line and executes the instructions at that particular line at the same time.

  • Interpreters are generally faster at first execution compared to a compiler, but slower at subsequent executions of the same code.

  • Interpreters usually produce codes that are cross-platform.

  • Some interpreted languages include Python, PHP, and Perl.

Compilation

Compilation is another way to translate high-level language codes into machine code using compilers.

Compilers will compile these codes first before execution. That is, they will first convert the program codes into machine codes, and then commit them to memory before they start execution of said code.

  • Compilers are faster after the first execution of the same code that has not changed since compilation. This is because if there is a change in the code, it will be re-compiled.

  • Compilers are not cross-platform, which implies that they are platform dependentThere are a number of techniques that can be used to address this problem..

  • Examples of compiled languages include Java, C, and C++.

Assembling

Assembling is a translation method used to convert assembly language codes into machine codes. Assembly language codes are mnemonic code, very similar to machine code.

Assembly language codes are difficult to understand unless studied carefully.

These concepts answer our earlier question of how digital computers understand our code jargon. We can now move on to the differences between compile-time and runtime.

What is compile-time?

Compile-time is the time period when a program code is translated into a low-level code or machine code, either by a compiler or an interpreter. Compile-time is the period of time from the beginning to the end of the process.

What is runtime?

Runtime refers to the time when the converted code, which is now in low level or machine code, is executed. In other words, runtime refers to the time when the code does what it was written to do.

Take a look at the image below for a pictorial explanation.

Source:Baeldung.com

Runtime vs. compile-time

Runtime and compile-time are compared and contrasted in the table below.

Runtime

Compile-time

The time period during code execution.

The time period during code translation.

Errors caught here will cause your program code to behave abnormally or to terminate unexpectedly. Fatal errors in PHP would do this.

Most of your program errors are caught here. For example, syntax, warning, and notice errors in PHP.

Cares less about object and function information as it doesn't know them, and only carries out the action associated with them.

Proper understanding of functions and objects, and assigns needed properties.

The codes are in the form of zeros and ones or a very similar one.

Codes are in human readable forms.

Errors caught here are usually not noticed during development and debugging.

Errors caught here can be easily fixed and corrected.

What comes at the end of the runtime is the result of computation or action performed by the computer, whatever it may be.

The output is a machine code that is understandable by computers.