Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Underscore isEqual, fast-deep-equal test
(version: 0)
Test on isEqual performance
Comparing performance of:
underscore.isEqual Level 5 vs fast-deep-equal.isEqual Level 5
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js'></script> <script type="text/javascript"> window.underscore = _; _ = null; </script>
Script Preparation code:
function equal(a, b) { if (a === b) return true; if (a && b && typeof a == 'object' && typeof b == 'object') { if (a.constructor !== b.constructor) return false; var length, i, keys; if (Array.isArray(a)) { length = a.length; if (length != b.length) return false; for (i = length; i-- !== 0;) if (!equal(a[i], b[i])) return false; return true; } if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags; if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf(); if (a.toString !== Object.prototype.toString) return a.toString() === b.toString(); keys = Object.keys(a); length = keys.length; if (length !== Object.keys(b).length) return false; for (i = length; i-- !== 0;) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false; for (i = length; i-- !== 0;) { var key = keys[i]; if (!equal(a[key], b[key])) return false; } return true; } // true if both NaN, false otherwise return a!==a && b!==b; }; // 5 levels deep window.foo5 = { a: 1, b: 2, c: { a: 1, b: 2, c: { a: 1, b: 2, c: { a: 1, b: 2, c: { a: 1, b: 2 } } } } }; window.bar5 = { a: 1, b: 2, c: { a: 1, b: 2, c: { a: 1, b: 2, c: { a: 1, b: 2, c: { a: 1, b: 4 } } } } };
Tests:
underscore.isEqual Level 5
underscore.isEqual(window.foo5, window.bar5)
fast-deep-equal.isEqual Level 5
equal(window.foo5, window.bar5);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
underscore.isEqual Level 5
fast-deep-equal.isEqual Level 5
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested, compared, and their pros and cons. **Benchmark Definition** The benchmark is testing two functions: `underscore.isEqual` and `fast-deep-equal.isEqual`. These functions are designed to compare two objects or values for equality. The benchmark definition is as follows: 1. **`underscore.isEqual(window.foo5, window.bar5)`**: This test case uses the `_` variable from the Underscore.js library to call the `isEqual` function on the `foo5` and `bar5` objects. 2. **`equal(window.foo5, window.bar5);`**: This test case defines its own `equal` function, which is used for comparison. **What's Being Compared** The benchmark compares the performance of two functions: * `underscore.isEqual`: A function from the Underscore.js library designed to compare objects or values for equality. * `fast-deep-equal.isEqual`: A custom implementation of an equality test, which is also used in this benchmark. **Options Compared** The benchmark compares the performance of two options: 1. **`underscore.isEqual`**: Uses a complex, object-based algorithm to compare objects and values for equality. 2. **`fast-deep-equal.isEqual`**: A custom implementation that uses various techniques, such as: * Checking if both NaN (Not a Number) values are equal. * Verifying the constructor of an object. * Comparing the `valueOf` and `toString` methods. **Pros and Cons** * **`underscore.isEqual`** * Pros: * More comprehensive comparison, covering various scenarios. * Uses a well-tested library. * Cons: * May be slower due to its complex algorithm. * **`fast-deep-equal.isEqual`** * Pros: * Optimized for deep comparisons and potentially faster than `underscore.isEqual`. * Customizable. * Cons: * Less comprehensive comparison, as it relies on specific techniques. **Library and Syntax** The benchmark uses the Underscore.js library, which is a utility library providing functional programming helpers. The `_` variable is used to access the `isEqual` function from the library. There are no special JavaScript features or syntax mentioned in this benchmark. **Other Alternatives** If you were considering alternative implementations for equality testing, some options might include: * **JSON equality libraries**: Libraries like `fast-json-equal` or `json-equal` provide optimized equality tests specifically designed for JSON data. * **Primitive comparison functions**: Functions like `==` or `===` can be used for simple comparisons between primitive values. However, these may not handle complex object comparisons as well as the benchmarked implementations. In summary, the benchmark compares the performance of two different approaches to testing equality: one using a popular library (`underscore.isEqual`) and another implementing it custom (`fast-deep-equal.isEqual`). The choice between these options depends on your specific needs, with `underscore.isEqual` providing more comprehensive coverage but potentially slower performance.
Related benchmarks:
object compare
fast compare test
fast compare test w/lodash 3
lodash.isEqual vs fast-deep-equal
Comments
Confirm delete:
Do you really want to delete benchmark?