更新时间:2022-02-10 04:08:55
我增加了循环并禁用了输出(显示时速度要慢得多).
而且我不是 Python 专家.但是您可以使用jit编译器pypy来加快python代码的速度,例如(但仍然比luajit慢.)此外,有关python3和python2的主题 可能对你也很有趣.
I've increased your loops and disable the output (it's much slower when it's displayed).
And I'm no python expert. But you can speed up your python code with the jit compiler pypy e.g. (but still slower than luajit.)
Furthermore, this topic about python3 and python2 might be interesting for you too.
r=0
for i in range(1,10000):
for j in range(1,10000):
r=i*j
$ time python3 loop.py
real 0m16.612s
user 0m16.610s
sys 0m0.000s
$ time python2 loop.py
real 0m11.218s
user 0m11.190s
sys 0m0.007s
$ time pypy loop.py
real 0m0.923s
user 0m0.900s
sys 0m0.020s
local r=0
for i=1,10000,1 do
for j=1,10000,1 do
r=i*j
end
end
$ time lua loop.lua
real 0m1.123s
user 0m1.120s
sys 0m0.000s
$ time luajit loop.lua
real 0m0.074s
user 0m0.073s
sys 0m0.000s