Disclaimer

I am the creator and main developer of Brython. I am aware that you might think I’m biased ! The test conditions are explained in detail below so that anyone can easily reproduce them and compare with the results presented here ; if something is wrong please post a comment and I will update this article.

Tested features

The test compares the speed of basic actions :

– assignement to an integer or a float

– augmented assignment on an integer

– building a dictionary, assigning a value to a key in a dictionary

– building a list, setting the value at a given rank

– addition of integers and strings

– casting an integer to a string

– create and run a simple function

How the test is run

The test is performed by running a single script made of all the elementary benchmarks. The source code of this script is here http://brython.info/speed/bench_str.py. The online editors or consoles are

Brython : http://brython.info/tests/index.html (with the debug checkbox unchecked)

Skulpt : http://www.skulpt.org/

pypy.js : http://pypyjs.org/demo/

For Python, the script is executed on the command line.

For Brython and Skulpt, the code is copied in the editor and executed by hitting the button “run”.

For pypy.js, I tried pasting the code in a single multi-line string with :

>>> src = """<code>"""

but this raised an exception in the console :

debug: OperationError: debug: operror-type: SyntaxError debug: operror-value: ('EOL while scanning string literal', ('c callback', 1, 12, 'r = c.push(\'src="""import time

', 0)) debug: OperationError: debug: operror-type: KeyError debug: operror-value: 'r'

So I generated a single-line version of the source code (see here http://brython.info/speed/bench_str_pypy.txt) and executed it with

>>> src = """<single line code>""" >>> exec(src)

The script is run 5 times for each solution ; the result for each individual test is the geometric mean of these 5 tests.

Configuration

All the tests are run on a PC with Windows 7. The browser is Firefox version 35.0.1 ; it is restarted after the tests for a solution are done.

The tests were made on March 27, 2015 with the version available online at that date.

Results

Execution time (ms) | X slower than CPython Cpython Brython pypy.js skulpt | Brython pypy.js skulpt assignment.py 125 14 3310 5819 | 0.11 26.57 46.70 augm_assign.py 211 44 4120 6791 | 0.21 19.56 32.24 assignment_float.py 110 508 3405 6048 | 4.63 31.04 55.13 build_dict.py 360 3490 3617 14539 | 9.70 10.05 40.41 set_dict_item.py 191 97 4820 23063 | 0.51 25.26 120.85 build_list.py 311 50 3428 6857 | 0.16 11.02 22.04 set_list_item.py 181 63 3330 8150 | 0.35 18.40 45.04 add_integers.py 249 113 4064 7691 | 0.45 16.34 30.92 add_strings.py 429 270 3972 8481 | 0.63 9.26 19.77 str_of_int.py 60 168 796 2272 | 2.81 13.36 38.15 create_function.py 240 3443 3570 8912 | 14.38 14.91 37.21 function_call.py 271 1446 3343 23341 | 5.33 12.33 86.09

Conclusion

It is hard to draw conclusions on the relative speed of implementations because it depends on the code executed. This benchmark tests very short scripts which may not be representative of real-world programs. All I can say is that with these tests, with the versions available on line on the day of the benchmark executed in the same PC and browser, Brython is generally faster than pypy.js, which is itself faster than Skulpt.