파이썬은 왜 느릴까? 느린가? (파이썬 종류에 따라서 천차만별임을 염두..)
왜 항상 자바는 c++ 보다 느릴까? (언제 쓰여진건지 모르겠군요. 항상이란 말이 좀 깨림칙...)
왜 인터프리트 언어는 컴파일언어보다 느릴까?
C++ VS Python 속도비교
스택 오버플로우의 답변 중 하나
All answers seem to miss the real important point here. It's the detail how "interpreted" code is implemented.
Interpreted languages are slower because their method, object and global variable space model is dynamic. This requires many many extra hash-table lookups on each access to a variable or method call. This is where most of the time is spent. It is a painful random memory lookup, which really hurts when you get a L1/L2 cache-miss.
The technique is well explained in the Deutsch/Schiffman paper "Efficient Implementation of the Smalltalk-80 System".
The question why php, python and ruby aren't doing this is pretty simple to answer: the technique is extremely complicated to implement.
가장 심플한 답변
A compiled language like C is usually compiled directly into machine code. When you run the code, it is executed directly by the CPU.
A fully interpreted language like BASIC or PHP is usually interpreted each time it runs. When you execute your code, the CPU executes the interpreter, and the interpreter reads and executes your source code. (PHP can be classified as fully interpreted, since while it does use opcodes, they are usually thrown away after the execution.)
A bytecode interpreted language like Python, is compiled from source code to bytecode that is executed by a virtual machine. The CPU runs the VM, and the VM executes each bytecode instruction. In Python, the bytecode is compiled the first time code is executed.
In Java, bytecode is compiled ahead of execution. The Java VM also has a special feature called Just-in-time compilation. This means that during execution, it may compile some of the bytecodeto machine code, which it can send to the CPU to execute directly.
In conclusion, with compiled languages, the CPU runs the code directly. In interpreted languages, the CPU usually runs the interpreter or virtual machine. This makes interpreted languages generally slower than compiled languages, due to the overhead of running the VM or interpreter.
NOTE: While we speak of interpreted and compiled languages, what we are really discussing is the usual execution style of a language. PHP can be compiled (using HipHop), and C can be interpreted (using Parrot VM).