-
-
Save davemackintosh/4feed6df6ea703e3c594 to your computer and use it in GitHub Desktop.
Mini benchmark Hoek.unique vs Set
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict" | |
// used in benchmarks. | |
const SAMPLE = 5000000 | |
const Hoek = require('hoek') | |
const array = [] | |
for (let i = 0; i < SAMPLE; ++i) { | |
array.push(i * Math.floor(Math.random() * (10 - 1 + 1)) + 1) | |
} | |
const sorted = array.sort() | |
console.time('hoek unsorted') | |
const result = [] | |
for (let i = 0; i < array.length; ++i) { | |
result.push(array[i]) | |
} | |
const resultHoek = Hoek.unique(result) | |
console.timeEnd('hoek unsorted') | |
console.time('set unsorted') | |
const result2 = new Set() | |
for (let i = 0; i < array.length; ++i) { | |
result2.add(array[i]) | |
} | |
const result2Set = Array.from(result2) | |
console.timeEnd('set unsorted') | |
console.time('hoek sorted') | |
const result3 = [] | |
for (let i = 0; i < sorted.length; ++i) { | |
result3.push(sorted[i]) | |
} | |
const resultHoek2 = Hoek.unique(result3) | |
console.timeEnd('hoek sorted') | |
console.time('set sorted') | |
const result4 = new Set() | |
for (let i = 0; i < sorted.length; ++i) { | |
result4.add(sorted[i]) | |
} | |
const result2Set2 = Array.from(result4) | |
console.timeEnd('set sorted') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
reference