Closed rodenmonte closed 6 years ago
NOTE: From a few benchmarks on my own machine, this implementation is at least as fast as https://github.com/jonschlinkert/is-primitive/pull/2/files, although I'm not sure why that method is not faster -- Looks like it's doing fewer comparisons.
pRTwoMethod x 2,531,482 ops/sec ±0.64% (86 runs sampled)
if x 2,549,438 ops/sec ±0.79% (88 runs sampled)
switch x 2,455,527 ops/sec ±0.80% (87 runs sampled)
I did not get different results in terms of order after running the benchmark 8 times, although sometimes the benchmark concluded there was not a significant difference between pRTwoMethod
and if
.
This is slightly faster than the switch-case. Here's the test results, just you know they got ran:
Benchmarks are slightly faster. The differences are statistically significant according to
benchmark
. No offense taken if you decide that the switch-case is elegant enough to prefer over a tiny speed increase. Here's the benchmarks for visibility: