On Sun, Aug 19, 2012 at 10:29 AM, Raymond Irving <xwis...@gmail.com> wrote:

> Hello,
>
> What could have cause PHP to start out so great but then slows to a crawl?
> Could it be the GC?
>
> Number of iterations Node.js PHP
> ---------------------------------------------------------------
> 100                         2.00         0.14
> 10’000                 3.00         10.53
> 1’000’000                 15.00 1119.24
> 10’000’000                 143.00 10621.46
> 1’000’000’000         11118.00 1036272.19
>
> See the script here:
>
> http://net.tutsplus.com/tutorials/javascript-ajax/node-js-for-beginners/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+nettuts+%28Nettuts%2B%29
>
> Is there any way that this can be improved?
>

PHP doesn't slow to a crawl. It runs in constant time. You can see that
because increasing the iteration count by 2 orders of magnitude increases
runtime by two orders of magnitude.

What you're seeing with nodejs is v8's JIT compiler in action. The
compilation step takes some extra time, which you only see the benefit from
in high iteration counts. It compiles the code down to machine code (which
prob takes the majority of the time), and then executes it. Where PHP
executes the same code each time. Which is why PHP is significantly faster
in the shorter iteration counts (it doesn't have the overhead of converting
to machine code).

Now, it looks like a surprising result. But it's far from a realistic
benchmark. For the narrow use-case where you're doing high iteration counts
over a simple (to a compiler) instruction set, v8 may be 93% faster. But
for the general use case, you won't find that big of a difference...

Nothing is free. Everything costs something. And that's the problem with
simple benchmarks like this. They hide the cost, and only show you the
result. Which is unrelistic at best...

Anthony

Reply via email to