Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Uint8array equality benchmark
(version: 0)
Test on isEqual performance
Comparing performance of:
_.isEqual Level 1 vs JSON.stringify Level 1 vs Naive array equals
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Script Preparation code:
window.data1 = new Uint8Array([...Array(1000).keys()].map(k=>k%8)) window.data2 = new Uint8Array([...Array(1000).keys()].map(k=>k%8)) window.arrayEquals = function(a, b) { return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((val, index) => val === b[index]); }
Tests:
_.isEqual Level 1
_.isEqual(window.data1, window.data2)
JSON.stringify Level 1
JSON.stringify(window.data1) === JSON.stringify(window.data2);
Naive array equals
window.arrayEquals(window.data1, window.data2)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
_.isEqual Level 1
JSON.stringify Level 1
Naive array equals
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:149.0) Gecko/20100101 Firefox/149.0
Browser/OS:
Firefox 149 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.isEqual Level 1
607906.4 Ops/sec
JSON.stringify Level 1
18043.6 Ops/sec
Naive array equals
4516913.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview of the Benchmark** The provided benchmark compares the performance of three different methods to check for equality between two Uint8Array objects: `_.isEqual` from Lodash, JSON string comparison using `JSON.stringify`, and a naive implementation of array equals. **Methods Compared** 1. **_.isEqual (Lodash)**: This method uses the `isEqual` function from Lodash, which recursively compares two values by checking if they are arrays or not. It returns true if both values have the same length and all elements at the same index are equal. 2. **JSON.stringify**: This method converts both input values to JSON strings and then compares these strings for equality using a simple string comparison (`===`). 3. **Naive Array Equals**: This implementation simply checks if the two arrays have the same length and then iterates over each element, checking if they are equal. **Pros and Cons** * **_.isEqual (Lodash)**: + Pros: Efficiently handles complex data structures, such as nested objects or arrays. + Cons: Requires Lodash library to be included, which may add unnecessary overhead. * **JSON.stringify**: + Pros: Simple to implement, doesn't require any external libraries. + Cons: May not perform well for large datasets due to the overhead of converting data to strings. * **Naive Array Equals**: + Pros: Easy to understand and implement, no dependencies required. + Cons: May be slower than _.isEqual for large datasets. **Library Used** The `_.isEqual` function from Lodash is used in the benchmark. Lodash is a popular JavaScript utility library that provides various functions for tasks such as data manipulation, string manipulation, and functional programming. **Special JS Feature/Syntax** There is no special JS feature or syntax used in this benchmark, apart from using modern JavaScript features like `let`/`const` variables and template literals. **Other Alternatives** If the naive array equals approach is not acceptable due to performance concerns, other alternatives could be: * Using a dedicated library like `fast-equal` or `array-equal` * Implementing a custom algorithm for array comparison, such as using bitwise operations * Using a more efficient data structure, like a `Uint8Array` view with a custom comparator Keep in mind that the choice of alternative will depend on the specific requirements and constraints of your project.
Related benchmarks:
Array#push vs Array#apply
Lodash, Set, Array comparison v2
Lodash, Set, Array, Native comparison
array[0] vs array.at(0) on 100000 elements
Array.map vs preallocation ckck
Comments
Confirm delete:
Do you really want to delete benchmark?