void main() { long int s = 0; int i; for (i 0; i < 10000000; i++) s := i; printf("%ld\n", s); }
optimized C | 3ms |
LuaJIT | 20ms |
unoptimized C | 30ms |
Lua | 100ms |
PHP | 200ms |
JavaScript V8 engine | 500ms |
Perl | 600ms |
JavaScrip Mozilla | 900ms |
Python2 | 1200ms |
Python3 | 1700ms |
PostgreSQL SQL | 1700ms |
PLpgSQL | 2200ms |
I repeat, this test has very small value for life - Only C language from this list is designed for heavy numeric operations. All other languages has designed for different purposes and in their typical domain the typical bottleneck will be elsewhere than in simple numeric calculation. But can be interesting, how modern computers are fast - for example PLpgSQL is designed as SQL glue (I know, so it is absolutely without any optimization, and expr evaluation is really expensive there (due repeated security, database checks) - I hope so nobody use PLpgSQL for heavy numeric calculations, and still), and it is able do 10M operations in 2 sec.
For Python you should also measure speed of our secret weapon called PyPy (https://pypy.org).
ReplyDeletefor a program like this:
```
def main():
s = 0
for i in range(10000000):
s += i
print(s)
main()
````
I get 498ms on CPython 3.5 and 75ms on PyPy 6.0 (that implements Python 3.5).
Apparently something got lost in translation. "for (i in 1; ..." presumably is "for (i = 0; ..." ? And for "s := i", maybe you meant "s += i" (as exemplified by the Python comment above)?
ReplyDeleteTry D, please. On my machine, it runs about 1/3 to 1/2 faster than C (ldc2 vs. gcc):
---
import std.stdio;
void main()
{
long s = 0;
for (int i = 0; i < 10000000; ++i)
s += i;
writeln(s);
}
---
@Joe, yes, I rewrite it to blog badly. I am not able to measure times below 1ms - so I have to believe, so it is fast
ReplyDelete