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) {
let jointArray = []
arrays.forEach(array => {
jointArray = [...jointArray, ...array]
});
return [...new Set([...jointArray])]
}
// 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
}
function combiningArrays(...arrays) {
const resultArray = [];
arrays.forEach(array => {
array.forEach(element => {
if (resultArray.indexOf(element) === -1) {
resultArray.push(element);
}
})
})
return resultArray;
}
function combiningArraysTwo(...arrays) {
const resultArray = [];
arrays.forEach(array => {
array.forEach(element => {
if (!resultArray.includes(element)) {
resultArray.push(element);
}
})
})
return resultArray;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Using iterations |
| ready |
Using iterations with contains |
| ready |
Using .reduce() |
| ready |
Using sets |
| ready |
Using .filter() |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.