If I do the following:
var abs = Math.abs;
Shoudn't abs(-10)
be faster than Math.abs(-10)
? Because abs is called directly.
This is what called my attention: Math.abs vs custom abs function
Update:
The same test performed in the Internet Explorer 11 shows a completely different result:
I'd speculate that this is due to some optimizations on built-in functions in Chrome's V8 Engine.
A test created by nnnnnn that clarifies what I am trying to say: Property shortcut
var shortcut = someObj.someOtherObj.someFunc
you can then avoid having to do property lookups if you useshortcut()
... Assuming the variable is local to where you're using it... – Selffertilizationvar abs0 = Math.abs;
is the local one in that test – Vanderpoolvar
maybe it's creating closure or at every function call it's pass that variable as arguments to that function... or something else. look at jsPerf without var statements – After