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
function getIntersectMap(arr, map) {
const returnMap = new Map()
for (let i = 0; i < arr.length; i++) {
if (!map.size) {
returnMap.set(arr[i], i)
} else {
if (map.has(arr[i]) && !returnMap.has(arr[i])) {
returnMap.set(arr[i], i)
}
}
}
return returnMap
}
function intersect_isamrish() {
const initialMap = new Map()
const arrays = Array.from(arguments) // I am assuming, all the arguments will be arrays.
const resultMap = arrays?.reduce(function _(acc, currentVal) {
return getIntersectMap(currentVal, acc)
}, initialMap)
return Array.from(resultMap.keys())
}
function intersect_blackholesinthesky(...arrays) {
const [smallestSet, ...otherSets] = arrays.map((arr) => new Set(arr)).sort((a, b) => a.size - b.size);
return Array.from(smallestSet.values()).filter((val) => otherSets.every((set) => set.has(val)));
}
function intersect_jeremrx(...arrays) {
return arrays?.reduce((intersection, currentArray) => {
const intersectionSet = new Set(intersection);
return currentArray.filter((item) => intersectionSet.has(item));
});
}
function intersect_jeremrx_2(firstArray, ...otherArrays) {
const intersection = new Set(firstArray);
otherArrays.forEach((array) =>
array.forEach((item) => intersection.has(item) || intersection.delete(item))
);
return [...intersection];
}
const arrstr__1 = [
"Item 1",
"Item 2",
"Item 3",
"Item 4",
"Item 5",
"Item 6",
"Item 7",
]
const arrstr__2 = ["Item 6", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7"]
const arrstr__3 = ["Item 4", "Item 7", "Item 5", "Item 6", "Item 8", "Item 9"]
const arrstr__4 = ["Item 7", "Item 5", "Item 6", "Item 8", "Item 9", "Item 10"]
const arrstr__5 = ["Item 6", "Item 7", "Item 5", "Item 8", "Item 9", "Item 10"]
Ready to run.
Test | Ops/sec | |
---|---|---|
isamrish |
| ready |
blackholesinthesky |
| ready |
jeremrx |
| ready |
jeremrx reworked |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.