3 ms·
But, there's no way that PHP is nearly 100 times slower I too am confused that it's only 100x slower. Consider the operation "2 + 2". In Java with JIT on, th
by jrockway 17y ago
But, there's no way that PHP is nearly 100 times slower
I too am confused that it's only 100x slower. Consider the operation "2 + 2". In Java with JIT on, this eventually becomes a single instruction, "add". (Ideally 2 and 2 are already in registers from previous manipulation in the function, and you don't even need a "load".)
In PHP, this operation is hundreds of instructions. You start with the AST node. Then you look up the variable names. Then you look up their bindings (fast because PHP has no scope, in Real Languages this is at least a linked-list traversal). Then you finally get the object representing the value. Now it needs to be coerced into the right type for +. Once that is done, we can finally run the add operation. Then the result needs to be boxed.
You are surprised that that is 100x slower than a native CPU instruction?