Last active
August 29, 2015 14:23
-
-
Save fcamel/beef85e5c3b9ab78507b to your computer and use it in GitHub Desktop.
Benchmark CPython2, PyPy, Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat h.py | |
n = 100000; | |
d = {}; | |
for _ in xrange(1000): | |
for k in xrange(n): | |
if k not in d: | |
d[k] = k * 2 | |
else: | |
d[k] += 1 | |
print d[n - 1] | |
$ time python h.py | |
200997 | |
real 0m22.513s | |
user 0m22.499s | |
sys 0m0.008s | |
$ time pypy h.py | |
200997 | |
real 0m5.091s | |
user 0m5.051s | |
sys 0m0.024s | |
$ cat h.js | |
n = 100000; | |
d = {}; | |
for (i = 0; i < 1000; i++) { | |
for (k = 0; k < n; k++) { | |
if (!(k in d)) { | |
d[k] = k * 2; | |
} else { | |
d[k] += 1; | |
} | |
} | |
} | |
console.log(d[n - 1]); | |
$ time nodejs h.js | |
200997 | |
real 0m2.939s | |
user 0m3.134s | |
sys 0m0.043s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment