Throw out the result first,
run java:
end i:1000000000 count:499999999500000000 time:0.638
run C:
end i:1000000000 count 499999999500000000 time:0.641424
run go:
end i:1000000000 count:499999999500000000 time:1.277728
run pypy:
end i:1000000000 count:499999999500000000 time:3.81583285332
run php
end i:1000000000 count:499999999500000000 time:26.515455007553
run nodejs:
end i:1000000000 count:499999999500000000 time:148.331
run python:
^Tend i:1000000000 count:499999999500000000 time:193.98550415
The above results have optimized the performance of golang and c.
This result is beyond my expectations.
1. Neither c nor golang has started optimization. So the performance is only in the middle position. As a reference time
2, java, nodejs and pypy, all using JIT can operate very quickly. (It is related to the current test algorithm, but it is indeed obvious that repeated operations It is helpful)
3. There is no obvious difference in the operation speed of static language and dynamic language. The key point is whether there is JIT
4. Python is too slow. I have always known it. Python is slow, but I didn’t expect it to be slower than PHP in terms of calculations.
5. Nodejs is not as ideal as large number processing. If BigInt is not used, it is indeed faster than PHP, python, and pypy.
ps:
1. Finally look forward to php8, because php8 comes with jit.
2.php has indeed missed better development. If accepted in 2011 After HHVM, you may no longer be in the same state. Things are like this. When you are at your peak, you will start to decline. Only by making constant changes will you remain invincible.
Test code:
https://gitee.com/goodtim/LangTest
The result of not optimizing golang and c, nodejs does not use BigInt processing:
run C:
end i:1000000000 count 499999999500000000 time:5.403450
run go:
end i:1000000000 count:499999999500000000 time:4.085926
run nodejs:
end i:1000000000 count:499999999067109000 time:2.568
run java:
end i:1000000000 count:499999999500000000 time:1.281
run php
end i:1000000000 count:499999999500000000 time:27.162304878235
run python:
end i:1000000000 count:499999999500000000 time:200.6685 12821
run pypy:
end i:1000000000 count:499999999500000000 time:3.82159590721