@@ -391,50 +391,11 @@ is exactly the same type of object that a lambda expression yields) is assigned!
391
391
Can Python be compiled to machine code, C or some other language?
392
392
-----------------------------------------------------------------
393
393
394
- Not easily. Python's high level data types, dynamic typing of objects and
395
- run-time invocation of the interpreter (using :func: `eval ` or :keyword: `exec `)
396
- together mean that a "compiled" Python program would probably consist mostly of
397
- calls into the Python run-time system, even for seemingly simple operations like
398
- ``x+1 ``.
399
-
400
- Several projects described in the Python newsgroup or at past `Python
401
- conferences <https://www.python.org/community/workshops/> `_ have shown that this
402
- approach is feasible, although the speedups reached so far are only modest
403
- (e.g. 2x). Jython uses the same strategy for compiling to Java bytecode. (Jim
404
- Hugunin has demonstrated that in combination with whole-program analysis,
405
- speedups of 1000x are feasible for small demo programs. See the proceedings
406
- from the `1997 Python conference
407
- <http://legacy.python.org/workshops/1997-10/proceedings/> `_ for more information.)
408
-
409
- Internally, Python source code is always translated into a bytecode
410
- representation, and this bytecode is then executed by the Python virtual
411
- machine. In order to avoid the overhead of repeatedly parsing and translating
412
- modules that rarely change, this byte code is written into a file whose name
413
- ends in ".pyc" whenever a module is parsed. When the corresponding .py file is
414
- changed, it is parsed and translated again and the .pyc file is rewritten.
415
-
416
- There is no performance difference once the .pyc file has been loaded, as the
417
- bytecode read from the .pyc file is exactly the same as the bytecode created by
418
- direct translation. The only difference is that loading code from a .pyc file
419
- is faster than parsing and translating a .py file, so the presence of
420
- precompiled .pyc files improves the start-up time of Python scripts. If
421
- desired, the Lib/compileall.py module can be used to create valid .pyc files for
422
- a given set of modules.
423
-
424
- Note that the main script executed by Python, even if its filename ends in .py,
425
- is not compiled to a .pyc file. It is compiled to bytecode, but the bytecode is
426
- not saved to a file. Usually main scripts are quite short, so this doesn't cost
427
- much speed.
428
-
429
- .. XXX check which of these projects are still alive
430
-
431
- There are also several programs which make it easier to intermingle Python and C
432
- code in various ways to increase performance. See, for example, `Cython <http://cython.org/ >`_ , `Psyco
433
- <http://psyco.sourceforge.net/> `_, `Pyrex
434
- <https://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/> `_, `PyInline
435
- <http://pyinline.sourceforge.net/> `_, `Py2Cmod
436
- <http://sourceforge.net/projects/py2cmod/> `_, and
437
- `Weave <https://docs.scipy.org/doc/scipy-dev/reference/tutorial/weave.html >`_.
394
+ `Cython <http://cython.org/ >`_ compiles a modified version of Python with
395
+ optional annotations into C extensions. `Nuitka <http://www.nuitka.net/ >`_ is
396
+ an up-and-coming compiler of Python into C++ code, aiming to support the full
397
+ Python language. For compiling to Java you can consider
398
+ `VOC <https://voc.readthedocs.io >`_.
438
399
439
400
440
401
How does Python manage memory?
0 commit comments