Differences between revisions 6 and 11 (spanning 5 versions)
Revision 6 as of 2008-08-12 22:22:04
Size: 1628
Editor: MichaelFoord
Comment:
Revision 11 as of 2008-11-15 13:59:37
Size: 2527
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
SEE:'''[wiki:Ten_things_people_want_to_know_about_Python Ten things people want to know about Python]'''for more details. SEE:'''[[Ten things people want to know about Python|Ten things people want to know about Python]]'''for more details.
Line 4: Line 4:
  * Why not ask:"Why is Python fast than the xxx language"?   * 'Faster' requires a bit of thought in practice. Language implementations, instead of language syntax, have a speed that can be measured on benchmarks. Python implementations can vary quite a bit, although dynamically typed languages usually perform slower than statically typed ones on standard benchmarks. As a practical matter, a profiler is necessary to understand performance. Python usually runs plenty fast.
Line 6: Line 6:
 Another answer::
  *
Python as a language is a set of rules (its syntax and semantics) and so doesn't have a 'speed'. Only a specific language implementation can have a measurable speed, and then we can only compare performance with a specific implementation of another language. In general you can't compare the speed of one language to another - you can only compare implementations.
First, the language implementations have speed, Python as a language is a set of rules (its syntax and semantics) and so doesn't have a 'speed'. Only a specific language implementation can have a measurable speed, and then we can only compare performance with a specific implementation of another language. In general you can't compare the speed of one language to another - you can only compare implementations.
Line 11: Line 10:
  Having said that, as a dynamic language Python will typically perform slower for specific benchmarks than standard implementations of some other languages (although it is faster than plenty of others). As a dynamic language a lot of information about the program can only be determined at runtime. This means that a lot of common compiler tricks, that rely on knowing the type of objects at compile time, can't work. Despite this there are a lot of things that can be done to improve the performance of dynamic language, several of which have been done before in virtual machines like Strongtalk and are being explored for Python in the PyPy JIT tracing compiler.   Having said that, as a dynamic language Python will typically perform slower for specific benchmarks than standard implementations of some other languages (although it is faster than plenty of others). As a dynamic language a lot of information about the program can only be determined at runtime. This means that a lot of common compiler tricks, that rely on knowing the type of objects at compile time, can't work. Despite this there are a lot of things that can be done to improve the performance of dynamic languages (beyond the performance of statically typed languages many believe), several of which have been done before in virtual machines like Strongtalk and are being explored for Python in the PyPy JIT tracing compiler.

  Finally, using an execution profiler, such as the Python profile or cprofile module, provides the critical information for speeding up execution. Most programs spend the majority of execution time in calls to operating system libraries and execution trade-offs are less intuitive. For example, many small requests for data across a network are much slower than a single, larger request. In practice, Python code execution is fast enough.

SEE:Ten things people want to know about Pythonfor more details.

Answer
  • 'Faster' requires a bit of thought in practice. Language implementations, instead of language syntax, have a speed that can be measured on benchmarks. Python implementations can vary quite a bit, although dynamically typed languages usually perform slower than statically typed ones on standard benchmarks. As a practical matter, a profiler is necessary to understand performance. Python usually runs plenty fast.

First, the language implementations have speed, Python as a language is a set of rules (its syntax and semantics) and so doesn't have a 'speed'. Only a specific language implementation can have a measurable speed, and then we can only compare performance with a specific implementation of another language. In general you can't compare the speed of one language to another - you can only compare implementations.

  • With Python there are several implementations - CPython (with or without Psyco, a specializing compiler for CPython), IronPython, Jython, PyPy - plus several partial implementations that implement a subset of Python (Tinypy) or can even compile a subset of Python to C++ (Shedskin). If you say Python is slow, which specific implementation are you talking about?

    Having said that, as a dynamic language Python will typically perform slower for specific benchmarks than standard implementations of some other languages (although it is faster than plenty of others). As a dynamic language a lot of information about the program can only be determined at runtime. This means that a lot of common compiler tricks, that rely on knowing the type of objects at compile time, can't work. Despite this there are a lot of things that can be done to improve the performance of dynamic languages (beyond the performance of statically typed languages many believe), several of which have been done before in virtual machines like Strongtalk and are being explored for Python in the PyPy JIT tracing compiler. Finally, using an execution profiler, such as the Python profile or cprofile module, provides the critical information for speeding up execution. Most programs spend the majority of execution time in calls to operating system libraries and execution trade-offs are less intuitive. For example, many small requests for data across a network are much slower than a single, larger request. In practice, Python code execution is fast enough.

Why is Python slower than the xxx language (last edited 2008-11-15 13:59:37 by localhost)

Unable to edit the page? See the FrontPage for instructions.