I've replicated your findings.
It's impressively about 4 TIMES faster.
Interestingly, if you compare the v.constructor and v typeof independently, performance-wise they are effectively the same.
The reason I've preferred v.constructor over typeof is because of its robustness factor; the v typeof returns false for explicit instantiations of types, eg. "new String()"
So what's happening here is a compiler optimization for typeof; where the compiler fails to optimize for the v.constructor.
This would actually be a bug, or at least an optimization deficiency, in the V8 compiler.
Because of the vagaries of compilers, we must perf-test our code and hunt out performance bottlenecks.
Good catch BeasTea,
I've replicated your findings.
It's impressively about 4 TIMES faster.
Interestingly, if you compare the v.constructor and v typeof independently, performance-wise they are effectively the same.
The reason I've preferred v.constructor over typeof is because of its robustness factor; the v typeof returns false for explicit instantiations of types, eg. "new String()"
So what's happening here is a compiler optimization for typeof; where the compiler fails to optimize for the v.constructor.
This would actually be a bug, or at least an optimization deficiency, in the V8 compiler.
Because of the vagaries of compilers, we must perf-test our code and hunt out performance bottlenecks.
Thx for ur explanation, that's impressive!!!