Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Benchmark CPython2, PyPy, Node.js
$ 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
You can’t perform that action at this time.