Closed chrisbolin closed 6 years ago
The Object.is class method is very close to === but differs in two ways:
===
NaN
Object.is
+0
0
> Object.is(NaN, NaN) true > NaN === NaN false > Object.is(+0, -0) false > +0 === -0 true
-0
Both of these are pretty minor cases
This check doesn't come for free.
Benchmarks on node 8.3.0 using master, Object.is, and the MDN polyfill.
8.3.0
master
The native method is about 17% slower, and the polyfill is about 7.5% slower.
--- speed tests: generic usage --- react-fast-compare x 175,552 ops/sec ±1.63% (87 runs sampled) react-fast-compare-object-is x 146,104 ops/sec ±2.18% (85 runs sampled) react-fast-compare-object-is-polyfill x 162,487 ops/sec ±1.62% (84 runs sampled) fastest: react-fast-compare --- speed tests: generic and react --- react-fast-compare x 140,986 ops/sec ±1.54% (85 runs sampled) react-fast-compare-object-is x 122,360 ops/sec ±1.07% (89 runs sampled) react-fast-compare-object-is-polyfill x 138,398 ops/sec ±1.42% (85 runs sampled) fastest: react-fast-compare,react-fast-compare-object-is-polyfill
Code for benchmarks is here: https://github.com/FormidableLabs/react-fast-compare/pull/9
Current decision: don't use Object.is() or a polyfill; the performance losses are too much.
Object.is()
The Object.is class method is very close to
===
but differs in two ways:NaN
vs.NaN
-===
treats these as unequal, butObject.is
treats them as equal+0
vs.0
-===
treats these as equal, butObject.is
treats them as unequalBenefits
NaN
as equal to itself+0
and-0
as separateBoth of these are pretty minor cases
Downsides
This check doesn't come for free.
Benchmarks on node
8.3.0
usingmaster
,Object.is
, and the MDN polyfill.The native method is about 17% slower, and the polyfill is about 7.5% slower.
Code for benchmarks is here: https://github.com/FormidableLabs/react-fast-compare/pull/9