Ask HN: Strange execution times of Javascript and PHP

https://news.ycombinator.com/item?id=2332626
by icode • 15 years ago
1 3 15 years ago

Hello HN,

just for fun I executed this in javascript:

  function test()
  {
   var r=1;
   for (var i=0;i<10000000;i++)
   {
    r*=1.0000001;
   }
   return r;
  }
  var start = (new Date).getTime();
  test();
  diff = (new Date).getTime() - start;
that gives me about 80ms

And this in PHP:

  function test()
  {
   $r=1;
   for ($i=0;$i<10000000;$i++)
   {
    $r*=1.0000001;
   }
   return $r;
  }
  $start = microtime(true)*1000;
  $r=test();
  echo "$r\n";
  $stop = microtime(true)*1000;
  echo $stop-$start."\n";
That gives me about 1300 ms on the command line and about 5000 ms when executed by apache.

Any ideas to explain these differences?

Related Stories

Loading related stories...

Source preview

news.ycombinator.com