Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash xor perf
(version: 0)
Searching for faster solution for _.xor(a, b)
Comparing performance of:
lodash xor vs with Sets
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function dec2hex (dec) { return dec < 10 ? '0' + String(dec) : dec.toString(16) } function generateId (len) { var arr = new Uint8Array((len || 40) / 2) window.crypto.getRandomValues(arr) return Array.from(arr, dec2hex).join('') } var a = [] var b = [] for( let i = 0; i < 1000; i++) { a[i] = generateId(16) b[i] = generateId(16) }
Tests:
lodash xor
const res = _.xor(a, b)
with Sets
var as = new Set(a) var bs = new Set(b) const res = a .filter((row_id) => bs.has(row_id)) .concat(b.filter((row_id) => !as.has(row_id)))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash xor
with Sets
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash xor
3463.2 Ops/sec
with Sets
7327.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the benchmark and explain what's being tested. **Benchmark Overview** The benchmark is testing two different approaches to calculating the XOR (exclusive or) of two arrays, `a` and `b`. The first approach uses Lodash's `_.xor` function, while the second approach uses JavaScript Sets. **Test Cases** There are two test cases: 1. **Lodash Xor**: This test case measures the performance of using Lodash's `_.xor` function to calculate the XOR of two arrays. 2. **With Sets**: This test case measures the performance of using JavaScript Sets to calculate the XOR of two arrays. **Options Compared** The two approaches have different strengths and weaknesses: * **Lodash Xor**: + Pros: Easy to use, well-maintained library with a large community. + Cons: May not be optimized for performance in certain cases. * **With Sets**: + Pros: Highly optimized for performance, can take advantage of modern CPU instructions. + Cons: Requires creating two Set objects and iterating over the arrays. **Library** In the Lodash Xor test case, the `_.xor` function is used. This is a popular utility library that provides various functions for functional programming tasks. In this case, it's being used to calculate the XOR of two arrays. **Special JS Feature/Syntax** None mentioned in the provided code snippets. **Benchmark Preparation Code** The preparation code generates two large arrays of random IDs using the `generateId` function and assigns them to variables `a` and `b`. **Other Alternatives** Some alternative approaches could be: * **Using a simple loop**: Instead of using Lodash's `_.xor` or JavaScript Sets, one could write a simple loop to calculate the XOR of two arrays. This would likely be slower than both of the above approaches. * **Using other libraries**: There are other libraries available that provide optimized implementations of array operations, such as Array.prototype.reduce() or Array.prototype.filter(). These might offer better performance than Lodash's `_.xor`. * **Native JavaScript implementation**: Some browsers and Node.js versions have native implementations of array operations, which might be faster than using a library like Lodash.
Related benchmarks:
lodash xor alternatives
lodash xor perf v2
lodash xor perf copy
lodash xor / sets / includes perf
Comments
Confirm delete:
Do you really want to delete benchmark?