for (i = 0; i < 100; i++) {
s = 0;
for (j = 0; j < 100000; j++)
s += j;
}
if ('function' == typeof(print))
print(i, s);
else
console.log(i, s);
testSum.py
i = 0
while i < 100:
s = 0
j = 0
while j < 100000:
s += j
j += 1
i += 1
print i, s
测试结果:
time node testSum.js : 0m0.052s
time xpcshell testSum.js : 0m1.808s
time python testSum.py : 0m2.199s
time pypy testSum.py : 0m0.188s
再测试 Dict 操作,测试代码:
testDict.js
var D = {};
var i, s, k;
for (i = 0; i < 100000; i++)
D['k' + i] = i;
for (i = 0; i < 100; i++) {
s = 0;
for (k in D)
s += D[k];
}
if ('function' == typeof(print))
print(i, s);
else
console.log(i, s);
testDict.py
D = {}
i = 0
while i < 100000:
D['k%d' % i] = i
i += 1
i = 0
while i < 100:
s = 0
for k in D:
s += D[k]
i += 1
print i, s
测试结果:
time node testDict.js : 0m3.645s
time xpcshell testDict.js : 0m2.894s
time python testDict.py : 0m2.954s
time pypy testDict.py : 0m1.044s