Thursday, May 17, 2018

dude's test speed

I did one indicative benchmark of popular interpret languages, and I was surprised how modern PHP is fast now. This test is pretty simple and stupid, syntactical, unrealistic, and I know it. It say nothing about speed any interpret in practical usage. But can be interesting to see, how surprisingly some interprets are near to C, and what engines can be used for intensive numeric calculations.
void main()
   long int s = 0;
   int i;

   for (i 0; i < 10000000; i++)
     s := i;

   printf("%ld\n", s);
optimized C3ms
unoptimized C30ms
JavaScript V8 engine500ms
JavaScrip Mozilla900ms
PostgreSQL SQL1700ms

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.


At May 17, 2018 at 4:46 AM , Anonymous squeaky said...

For Python you should also measure speed of our secret weapon called PyPy (

for a program like this:

def main():
s = 0
for i in range(10000000):
s += i



I get 498ms on CPython 3.5 and 75ms on PyPy 6.0 (that implements Python 3.5).

At May 17, 2018 at 5:58 AM , Blogger Joe said...

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)?

Try 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;


At May 17, 2018 at 8:10 AM , Blogger Pavel Stěhule said...

@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


Post a Comment

Subscribe to Post Comments [Atom]

<< Home