jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
// USING A SET
function mergeArraysSet(...arrays) {
return Array.from(new Set([].concat(...arrays)))
}
// USING .FILTER()
function mergeArraysFilter(...arrays) {
let jointArray = []
arrays.forEach(array => {
jointArray = [...jointArray, ...array]
})
const uniqueArray = jointArray.filter((item,index) => jointArray.indexOf(item) === index)
return uniqueArray
}
// USING .REDUCE()
function mergeArraysReduce(...arrays) {
let jointArray = []
arrays.forEach(array => {
jointArray = [...jointArray, ...array]
})
const uniqueArray = jointArray.reduce((newArray, item) =>{
if (newArray.includes(item)){
return newArray
} else {
return [...newArray, item]
}
}, [])
return uniqueArray
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Using .filter() |
| ready |
Using .reduce() |
| ready |
Using sets |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.