Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash xor perf v2
(version: 0)
Searching for faster solution for _.xor(a, b)
Comparing performance of:
lodash xor vs with Sets vs isEqual + sort vs diff x 2
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).length === 0;
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))).length === 0;
isEqual + sort
const res = _.isEqual(_.sortBy(a), _.sortBy(b));
diff x 2
const res = _.difference(a, b).length === 0 && _.difference(b, a).length === 0;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
lodash xor
with Sets
isEqual + sort
diff x 2
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash xor
4547.0 Ops/sec
with Sets
8690.5 Ops/sec
isEqual + sort
1407.9 Ops/sec
diff x 2
15437.4 Ops/sec
Related benchmarks:
lodash xor alternatives
lodash xor perf
lodash xor perf copy
lodash xor / sets / includes perf
Comments
Confirm delete:
Do you really want to delete benchmark?