Python이 Java / C #보다 느립니까?
Python이 Java / C #보다 느립니까?
성능 비교 c-java-python-ruby-jython-jruby-groovy
다음은 CPython을 최적화하는 프로젝트입니다. unladen-swallow
언어와 런타임을 혼동하지 마십시오.
Python (언어)에는 많은 런타임 구현이 있습니다.
CPython은 일반적으로 해석되며 네이티브 코드 C #보다 느립니다. Java JIT 컴파일러에 따라 Java보다 느릴 수 있습니다.
JYthon은 JVM에서 해석되며 Java와 동일한 성능 프로필을 갖습니다.
IronPython은 C #과 동일한 .NET 라이브러리 및 IL에 의존하므로 성능 차이는 비교적 적습니다.
Python은 PyREX, PyToC 등을 통해 네이티브 코드로 번역 할 수 있습니다. 이 경우 일반적으로 C ++만큼 잘 수행됩니다. 어느 정도까지는 C ++를 더 최적화하고 PyREX의 최적화되지 않은 출력보다 약간 더 나은 성능을 얻을 수 있습니다.
자세한 내용은 http://arcriley.blogspot.com/2009/03/so-long-pyrex.html을 참조하십시오.
Python (언어)은 느리지 않습니다. 일부 Python 런타임 (예 : CPython)은 네이티브 코드 C ++보다 느립니다.
Python이 Java / C #보다 느린 이유를 묻는 것은 옳지 않습니다. Java는 얼마나 빠릅니까? 순진한 인터프리터는 최적화 된 컴파일러보다 약 10 배 느립니다. JavaScript로 작성된 Java bytcode 인터프리터가 있다고 생각합니다. 아마도 그렇게 빠르지는 않을 것입니다. 따라서 의도 된 질문은 "CPython 언어 시스템이 동등한 Sun, IBM, Oracle JRE 및 Microsoft .NET 런타임보다 느린 이유는 무엇입니까?"입니다.
정답은 기술적이지 않다고 생각합니다. 가장 빠른 Java 및 .NET 런타임은 성능이 경쟁적인 환경에서 개발하는 대규모 기술 팀이 있기 때문에 더 빠릅니다.
동적 언어 시스템은 구현하기 쉽습니다. 어떤 바보라도 할 수 있습니다. 나는 가지고있다. 정적 언어 시스템은 설계 및 구현이 더 복잡합니다. 단순한 정적 시스템은 동일하게 작동하는 동적 시스템보다 훨씬 빠르게 실행되는 경향이 있습니다. 그러나 고도로 최적화 된 동적 시스템이 거의 같은 속도로 실행될 수 있습니다. 일부 스몰 토크 구현이 꽤 좋았다는 것을 알고 있습니다. 개발 된 동적 시스템의 자주 인용되는 예는 MIT Lisp Machine 입니다.
또한 실제 그 루트가 라이브러리 코드에 의해 수행되는 경우 언어 시스템은 중요하지 않을 수 있습니다. 대안으로, 언어는 일정한 요인 성능 차이를 쉽게 제거 할 수있는보다 효율적인 알고리즘을 개발하도록 장려 (또는 시간 (!)) 할 수 있습니다.
다른 답변에서 언급했듯이 이것은 런타임 시스템과 현재 작업에 따라 다릅니다. 따라서 표준 (C) Python이 반드시 Java 또는 C #보다 느리지는 않습니다. 일부 모듈은 C로 구현됩니다. 따라서 네이티브 구현의 속도 와 Python의 언어를 결합합니다.
우리는 작은 실험을했습니다. 우리는 다른 언어로 팩토리얼 계산의 실행 시간을 비교했습니다. 이 테스트는 실제로 임의 정밀도 정수 구현의 성능을 평가하기위한 것입니다.
피험자. 언어 임의 정밀도 정수 런타임
1. 자바 java.math.BigInteger JRE 6.13
2. .NET System.Numerics.BigInteger MS CLR 4.0
3. Python long Active Python 2.6.2.2
4. Squeak BigInt Squeak 3.10.2
5. .NET Mono.Math.BigInteger MS CLR 4.0
결과 :
1) 2) 3) 4) 5)
10.000! 343ms 137ms 91ms 1.200ms 169ms
20.000! 1.480ms 569ms 372ms 1.457ms 701ms
30.000! 3.424ms 1.243ms 836ms 3.360ms 1.675ms
40.000! 6.340ms 2.101ms 1.975ms 6.738ms 3.042ms
50.000! 10.493ms 3.763ms 3.658ms 10.019ms 5.242ms
60.000! 15.586ms 7.683ms 5.788ms 14.241ms 10.000ms
막대 차트는 결과를 보여줍니다. Python이 확실한 승자입니다. 내가 아는 한 파이썬은 Karatsuba 알고리즘 을 사용 하여 속도를 설명하는 큰 정수를 곱합니다.
게다가, 파이썬의 "임의 정밀도 정수"유형은 내장 long. 따라서 Java의 BigInteger 클래스에 필요한 특수 유형 처리도 필요하지 않습니다.
간단히 -Python은 느립니다 .
어떤 인터프리터 (현재 사용 가능)를 사용하든 Java 및 C보다 느립니다. 다양한 벤치 마크에서 Ruby 및 PHP보다 느립니다. 다른 사람의 대답에 의존하지 말고 자신을 확인하고 확인하십시오.
개인적으로 나는 파이썬을 더 빨리 얻는 데 많은 기여와 개발이 있다고 생각하지 않습니다. 파이썬에서는 생산성이 좋고 일부 문제를 바로 해결하기 때문에 속도 / 성능은 심각하게 고려되지 않습니다. Python의 성능 조정을 방해하는 아키텍처 문제도 있습니다.
면책 조항 -이 답변은 아마도 Python 애호가에게 해를 끼칠 것입니다. 저도 Python 개발자이며 Spring (Java)보다는 Django / Flask / Pyramid에서 웹앱을 개발하는 것을 좋아합니다. 그러나 나는 실제로 내 작업과 경험에서 Python이 얼마나 느린 지 확인합니다. 속도가 항상 내 우선 순위는 아닙니다. 그러나 나는 그들과 함께하는데, 파이썬 인터프리터는 적어도 마라톤에 서기 위해서는 기름칠과 기름칠을하거나 전체 엔진을 교체해야한다고 말한다. 주류 프로그래밍 언어입니다.
의견에서 제안했듯이 추론 할 수있는 테스트 사례를 실제로 제공해야합니다. 성능 차이의 원인은 실행중인 테스트에 따라 달라집니다.
그러나 나는 정적 대 동적 특성이 그것과 많은 관련이있을 수 있다고 제안합니다. 비가 상 호출의 경우 JIT로 컴파일 된 C # / Java는 JIT 시간에 정확하게 결정할 수 있으므로 매우 저렴합니다. 가상 통화조차도 단일 수준의 리디렉션을 포함합니다. 바인딩이 동적이 될 때 고려해야 할 사항이 더 다양합니다.
정확한 런타임 동작을 이해한다고 주장 할만큼 Python에 대한 세부 정보를 충분히 알지 못합니다. 버전과 구현에 따라 다를 수 있습니다. 그런 다음 가상 머신에 의해 실행되는 "파이썬 바이트 코드"와 같은 것이 있습니다.이 가상 머신이 실제로 JIT 컴파일을 수행하는지 여부는 또 다른 문제입니다.
이는 컴파일 단계가 작업 할 정보가 적기 때문에 덕 유형 (동적 유형) 언어의 경우 런타임에서 더 많은 작업을 수행해야한다는 사실로 귀결됩니다.
Thus if I am making the method invocation foo.bar(), in case of Java or C++ the invocation to bar can be optimized in the compilation process by discovering the type of "foo" and then directly invoking the method at the memory location where the compiler knows it will be found. Since a python or any other dynamically typed language compiler does not know what type the object foo belongs to, it has to do a type check at runtime and then look up the address of the bar method and then invoke it.
There are other difficulties a python compiler writer struggles with as well, though the one above hopefully adequately gives an indication. So even with the best compiler writers, statically typed languages are likely to perform much better at runtime.
Where dynamically typed languages score are typically in the development time. Due to fewer lines of code to write and maintain, and no compile wait times for developers, the development often goes through much faster.
What you got there is clear example of writing Java in Python:
def __init__(self,size):
self.first = None
last = None
for i in range(size):
current = Person(i)
if self.first == None : self.first = current
if last != None :
last.next = current
current.prev = last
last = current
self.first.prev = last
last.next = self.first
A bit more pythonic:
def __init__(self,size):
chain = [Person(i) for i in range(size)]
self.first = chain[0]
chain = zip(chain, chain[1:].append(chain[0]))
for p,n in chain:
p.next = n
n.prev = p
I think it's ultimately that Python doesn't go as far as it can with optimizations. Most of the optimization techniques that are common are for static languages. There are optimization techniques for dynamic languages, but the modern ones don't seem to make as much use of them as they could. Steve Yegge has an excellent blog post on the subject.
EDIT: I just wanted to point out that I'm not necessarily stating this to be critical of Python. I prefer simplicity over unnecessary speed any day.
It doesn't have anything to do with the languages themselves, it's just the fact that java implementation and runtime system (JVM) are very high quality, and that lots of resources have been invested in stability, scalability and performance improvements over the years.
Contrast that to the fact that CPython implementation just recently implemented eg threaded dispatch in its interpreter which gave it performance boost of up to 20% for certain problems. It's not a good thing as it sounds, it is bad because that kind of basic optimization should be there from the day one.
This type of question can't be answered just by qualitative reasoning, you need good benchmarks to back it up. Here's one set that compare Python 3 vs C# Mono and find Python to be 3 to 300 times slower. The Python vs. Java results are similar. (The usual cautions about interpreting benchmarks apply.)
These benchmarks also report the source code size, and Python was significantly more concise than Java and C#.
Since it's interpreted and not compiled.. it should be slower in execution time.
As a table mentioned in Code Complete (second edition) book, page 600,
C# equals C++ in execution time (1:1). And Python is slower above hundred times than C++ in execution time (>100:1).
And Java is slower than C++ by one time and a half (1.5:1).
These statistics are on average. I don't know who made this study, but seems interesting.
I think opposite. I can do simple program in Python faster than in Java, and those Python scripts work really fast.
Of course your question without examples is hard to answer. Maybe you have found slow library, bug etc. Give us more details please.
I would argue that the ease and simplicity of writing Python code makes it possible to write more complex code; for example, code that takes advantage of multi-core processors. Since per-core performance has been mostly stagnant for the past 5-10 years, I don't think it's clear that Python programs (whether they're running on CPython or something else) are slower in the long run.
참고URL : https://stackoverflow.com/questions/672857/is-python-slower-than-java-c
'program story' 카테고리의 다른 글
| 부트 스트랩 드롭 다운이 작동하지 않음 (0) | 2020.11.09 |
|---|---|
| NSDate를 사용하여 Swift 3에서 시간 (시, 분, 초)을 얻는 방법은 무엇입니까? (0) | 2020.11.09 |
| DataTable에서 특정 행 삭제 (0) | 2020.11.09 |
| WPF-표준 단추를 사용하여 위쪽 및 아래쪽 화살표가있는 단추 만들기 (0) | 2020.11.09 |
| didReceiveRemoteNotification : fetchCompletionHandler의 구문 분석 경고 (0) | 2020.11.09 |