jonschlinkert / is-primitive

Is the typeof value a javascript primitive?
MIT License
37 stars 9 forks source link

feat(bench): add oneTypeof, oneLiner and twoLiner tests #7

Open pi0 opened 6 years ago

pi0 commented 6 years ago

Hi! I've added 3 new variants to the benchmarks: oneTypeof, oneLiner and twoLiner.

Results

All tests was runned on MacBook Pro / 10.14. It seems that twoLiner is the winner in all runs.

Node 8

Run 1:

twoTypeof (current) x 3,550,837 ops/sec ±1.11% (87 runs sampled)
oneTypeof x 3,771,015 ops/sec ±0.72% (96 runs sampled)
oneLiner x 3,616,855 ops/sec ±0.65% (96 runs sampled)
twoLiner x 3,734,022 ops/sec ±1.16% (90 runs sampled)
if x 3,780,377 ops/sec ±0.91% (94 runs sampled)
negation x 3,498,913 ops/sec ±1.84% (91 runs sampled)
equals x 3,223,031 ops/sec ±3.88% (83 runs sampled)
equalsNot x 3,590,390 ops/sec ±1.15% (90 runs sampled)
switch x 3,589,515 ops/sec ±1.29% (90 runs sampled)
object x 2,083,978 ops/sec ±1.04% (89 runs sampled)
object - in x 2,308,644 ops/sec ±2.00% (87 runs sampled)
object - own x 2,481,388 ops/sec ±2.18% (84 runs sampled)
array x 1,343,607 ops/sec ±3.54% (85 runs sampled)
Fastest is if,twoLiner

Run 2:

twoTypeof (current) x 3,223,350 ops/sec ±4.97% (83 runs sampled)
oneTypeof x 3,373,441 ops/sec ±2.44% (84 runs sampled)
oneLiner x 3,530,979 ops/sec ±1.20% (88 runs sampled)
twoLiner x 3,789,479 ops/sec ±0.70% (95 runs sampled)
if x 3,676,408 ops/sec ±2.40% (92 runs sampled)
negation x 3,646,774 ops/sec ±0.57% (92 runs sampled)
equals x 3,672,144 ops/sec ±1.05% (94 runs sampled)
equalsNot x 3,742,456 ops/sec ±1.10% (91 runs sampled)
switch x 3,687,920 ops/sec ±1.17% (91 runs sampled)
object x 2,151,595 ops/sec ±0.98% (91 runs sampled)
object - in x 2,474,402 ops/sec ±0.87% (90 runs sampled)
object - own x 2,733,454 ops/sec ±0.87% (93 runs sampled)
array x 1,494,727 ops/sec ±0.69% (95 runs sampled)
Fastest is twoLiner,if

Node 10

Run 1:

twoTypeof (current) x 117,488,323 ops/sec ±0.93% (88 runs sampled)
oneTypeof x 117,681,424 ops/sec ±1.27% (89 runs sampled)
oneLiner x 117,480,971 ops/sec ±1.35% (92 runs sampled)
twoLiner x 118,184,360 ops/sec ±1.00% (91 runs sampled)
if x 28,237,352 ops/sec ±0.98% (89 runs sampled)
negation x 28,604,420 ops/sec ±0.66% (94 runs sampled)
equals x 33,609,823 ops/sec ±0.94% (91 runs sampled)
equalsNot x 48,137,146 ops/sec ±1.67% (88 runs sampled)
switch x 17,765,326 ops/sec ±1.20% (90 runs sampled)
object x 4,586,132 ops/sec ±0.76% (92 runs sampled)
object - in x 5,112,496 ops/sec ±0.59% (90 runs sampled)
object - own x 6,853,258 ops/sec ±1.64% (93 runs sampled)
array x 6,328,857 ops/sec ±1.70% (92 runs sampled)
Fastest is twoLiner,twoTypeof (current),oneTypeof,oneLiner

Run 2:

twoTypeof (current) x 117,605,753 ops/sec ±1.01% (88 runs sampled)
oneTypeof x 117,868,886 ops/sec ±0.84% (89 runs sampled)
oneLiner x 118,570,718 ops/sec ±0.75% (91 runs sampled)
twoLiner x 117,264,741 ops/sec ±1.00% (89 runs sampled)
if x 28,596,513 ops/sec ±1.04% (92 runs sampled)
negation x 28,212,960 ops/sec ±0.84% (92 runs sampled)
equals x 33,689,471 ops/sec ±0.66% (93 runs sampled)
equalsNot x 48,890,665 ops/sec ±0.83% (90 runs sampled)
switch x 18,495,350 ops/sec ±0.63% (94 runs sampled)
object x 4,184,827 ops/sec ±3.86% (86 runs sampled)
object - in x 4,790,887 ops/sec ±2.08% (88 runs sampled)
object - own x 6,980,963 ops/sec ±0.79% (91 runs sampled)
array x 6,388,749 ops/sec ±1.16% (92 runs sampled)
Fastest is oneLiner,oneTypeof,twoTypeof (current),twoLiner
pi0 commented 6 years ago

Node 0.x is failing because of usage of const in tests. Should we keep it?

jonschlinkert commented 6 years ago

Should we keep it?

I don't feel strongly either way, but I think it's okay if we drop support for Node.js 0.x. Thoughts?

Thanks for doing this!

pi0 commented 6 years ago

@jonschlinkert Friendly reminder about this PR :D

jonschlinkert commented 5 years ago

Can't believe I forgot about this PR for so long. Sorry @pi0! Before I merge, did you want to update the main export to use the function that was fastest in benchmarks? The current function did pretty well, so I'm fine with either way.

pi0 commented 5 years ago

NP @jonschlinkert. Sure will update branch 😊