Lesson 4 of 7

From Source Code to Machine Code

Source code reaches the CPU in one of three ways: compiled ahead of time, compiled just in time, or interpreted. You'll learn how each works and what it means for performance.

Ahead-of-time compilation (C, C++, Rust, Go, Swift): a translates the whole program to machine code once, before it runs. The is native instructions; startup is instant and speed is maximal, but the binary is built for one CPU architecture and OS.

Interpretation (classic Python, Ruby): a program (the ) reads your code — usually pre-parsed into simple bytecode — and performs each operation itself. A bytecode 'ADD' might cost the interpreter 50+ real instructions of dispatching, type checking, and boxing. Flexible and portable, 10-100x slower for tight .

Just-in-time (JIT) compilation (JavaScript's V8, the JVM, C#, PyPy): start by interpreting, watch which run hot, compile those to native machine code at runtime — optimizing for the types actually seen. That's how JavaScript became fast enough to run within a few times the speed of C for many workloads.

Text
The classic AOT pipeline (detailed in the Compilers track):

 source.c
   -> preprocessor  (expand #include, #define)
   -> compiler      (C -> assembly, optimizations here)
   -> assembler     (assembly -> object file: machine code)
   -> linker        (combine .o files + libraries -> executable)
 ./program

Rough single-thread speed for a numeric loop:
  C / Rust (AOT)      1x
  JS / Java (JIT)     1-3x slower
  Python (interp)     30-100x slower
  (NumPy escapes by calling AOT-compiled C under the hood)
Finished reading?Mark it done to track your progress.

Tip: use the ← and → keys to move between lessons.