I'm curious about these jsperf results. They appear to demonstrate that a direct function call is substantially faster than the same function called with .call
or .apply
. (The difference between .call
and .apply
surprised me even more.) Could you please explain these results?
Update: Here is a jsperf that someone left that tests .apply without a second array instantiation.
About 2.78 microseconds per function call.
Function calls in Javascript are less expensive than the maintenance nightmare caused by poorly-organized code.
Foreach performance is approximately 6 times slower than FOR / FOREACH performance. The FOR loop without length caching works 3 times slower on lists, comparing to arrays. The FOR loop with length caching works 2 times slower on lists, comparing to arrays.
I guess the cause might depend on which interpreter your are running the code on, but it seems that normal functions calls are faster because the interpreter can use Inline Cache to access the properties.
You can have a look here for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With