Monday, November 25, 2013

Pystone - PythonJS vs PyPy


The following Pystone benchmarks were performed with the default 50,000 iterations, the results are the average of five runs. PythonJS is tested in four different modes with greater levels of optimizations. Test machine is: dual core 2.4GHZ, 4GB RAM, LinuxMint with Google-Chrome v31.

PythonJS vs Brython and Empythoned

Above: Brython, Empythoned, PythonJS in default mode, and PythonJS with inlined optimization. PythonJS outperforms other browser based Python's: Empythoned (3,320 pystones) and Brython (425 pystones). PythonJS in default mode gets 8,150 pystones per-second. See Brython's JavaScript output here

PythonJS vs PyPy

Python2.7 reaches an average of 112,257 Pystones per-second. Pythonium (another Python to JavaScript translator) in its fastest veloce mode reaches an average of pystones 291,480 per-second. PythonJS in javascript mode, reaches an average of 850,120 Pystones per-second. PyPy-1.9 is the winner with an average score of 1,813,461 Pystones per-second.


Brython PythonJS Integration

I am also working on integrating Brython's tokenizer and parser into PythonJS so that PythonJS can be fully self hosted. The file in Brython's source code is py2js.js. It transforms Python code into its own abstract syntax tree that is very similar to the standard Python AST. I am making code to walk this tree and convert it into a standard AST that is required by the translator in PythonJS. See these files, and contact me if you would like to help.

2 comments:

  1. I miss +1 button again. Is Python 2 PythonJS able to figure out that class doesn't have any multiple parents and apply optimization dynamically?

    Have you thought about employing rule engine for this translation step, so that it can be debugged/inspected more fine-grained?

    ReplyDelete
  2. Multiple parents are not really an overhead anymore. PythonJS in default mode caches all the methods from all parents on the instance when the instance first created. In optimized "javascript" mode methods from all the parents get put on the sub-classes prototype - making its prototype chain flat and very fast.

    ReplyDelete