sudden questions

2025.12.8

Why C++ is faster than Python in many ways?

  1. Compiled vs. Interpreted
    C++: Compiler translate code into machine code directly.

    • When Running: CPU excecute instractions directly.

    Python: code -> Bytecode -> PVM (read line by line and excecute)

    • When Running: CPU runs VM, VM runs Python code.
  2. Static vs. Dynamic Typing

  3. Memory & Object Overhead

    a int variable: in C++ 4 Bytes, in Python is a PyObject struct and takes > 28 Bytes.

  4. C++ has Compiler Optimization

Python library’s underlying core code is C++/C !

作者

Zylll

发布于

2025-12-08

更新于

2025-12-08

许可协议