관리 메뉴

HAMA 블로그

인터프리터 언어는 컴파일 언어보다 느린가? 본문

소프트웨어 사색

인터프리터 언어는 컴파일 언어보다 느린가?

[하마] 이승현 (wowlsh93@gmail.com) 2015.08.01 17:49

파이썬은 왜 느릴까? 느린가?     (파이썬 종류에 따라서 천차만별임을 염두..) 

https://medium.com/@cookatrice/why-python-is-slow-looking-under-the-hood-7126baf936d7

https://hbfs.wordpress.com/2009/11/10/is-python-slow/


왜 항상 자바는 c++ 보다 느릴까?  (언제 쓰여진건지 모르겠군요. 항상이란 말이 좀 깨림칙...) 

http://sungpi.postach.io/post/wae-hangsang-jabajavaneun-c-boda-neuringa


왜 인터프리트 언어는 컴파일언어보다 느릴까?

http://stackoverflow.com/questions/1694402/why-are-interpreted-languages-slow

http://stackoverflow.com/questions/7991877/why-is-an-interpreter-slower-than-a-compiler-in-practice


C++ VS Python 속도비교 

http://blog.dhananjaynene.com/2008/07/performance-comparison-c-java-python-ruby-jython-jruby-groovy/

http://www.matthiaskauer.com/2014/02/a-speed-comparison-of-python-cython-and-c/


스택 오버플로우의  답변 중 하나

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.

Google's Javascript Core8 is so fast and targeting almost C speed for a simple optimization: they take the object data model as fixed and create internal code to access it like the data structure of a native compiled program. When a new variable or method is added or removed then the whole compiled code is discarded and compiled again.

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.

And only Google has the money to pay for JavaScript because a fast browser-based JavaScript interpreter is their fundamental need of their billion dollar business model.


가장 심플한 답변 

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.)

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).

0 Comments
댓글쓰기 폼