<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
var now = new Date()
window.foo = [{ one: 'cat', two: { one: 'dog', two: now } }, 'bird', ['yellow', 'green', { blue: 'purple' }]];
window.bar = [{ one: 'cat', two: { one: 'dog', two: now } }, 'bird', ['yellow', 'green', { blue: 'purple' }]];
_.isEqual(window.foo, window.bar)
JSON.stringify(window.foo) === JSON.stringify(window.bar);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
_.isEqual | |
JSON.stringify |
Test name | Executions per second |
---|---|
_.isEqual | 395616.2 Ops/sec |
JSON.stringify | 225621.8 Ops/sec |
Let's dive into the world of JavaScript microbenchmarks and explore what's being tested on MeasureThat.net.
Benchmark Definition JSON
The provided JSON defines two benchmark tests:
lodash.isEqual
(a utility function from the Lodash library) versus comparing the stringified versions of two complex object arrays (window.foo
and window.bar
) using the ===
operator.Options Compared
The two main options being compared are:
===
.Pros and Cons
Other Considerations
Alternative Approaches
Other alternatives to compare could include:
isEqual
function.Keep in mind that the choice of approach depends on the specific use case, performance requirements, and complexity of the data being compared.