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
var heroes = [
{ "name": "Rocco Siffredi", "age": 54, "long": true },
{ "name": "John Holmes", "age": 44, "long": true },
{ "name": "Peter North", "age": 61, "long": true },
{ "name": "Rocco Siffredi", "age": 54, "long": false }
];
var heroesLong = [
{ "name": "Rocco Siffredi", "age": 54, "long": true },
{ "name": "John Holmes", "age": 44, "long": true },
{ "name": "Peter North", "age": 61, "long": true },
{ "name": "Rocco Siffredi", "age": 54, "long": false },
{ "name": "Rocco Siffredi", "age": 54, "long": true },
{ "name": "John Holmes", "age": 44, "long": true },
{ "name": "Peter North", "age": 61, "long": true },
{ "name": "Rocco Siffredi", "age": 54, "long": false },
{ "name": "Rocco Siffredi", "age": 54, "long": true },
{ "name": "John Holmes", "age": 44, "long": true },
{ "name": "Peter North", "age": 61, "long": true },
{ "name": "Rocco Siffredi", "age": 54, "long": false },
{ "name": "Rocco Siffredi", "age": 54, "long": true },
{ "name": "John Holmes", "age": 44, "long": true },
{ "name": "Peter North", "age": 61, "long": true },
{ "name": "Rocco Siffredi", "age": 54, "long": false },
{ "name": "Rocco Siffredi", "age": 54, "long": true },
{ "name": "John Holmes", "age": 44, "long": true },
{ "name": "Peter North", "age": 61, "long": true },
{ "name": "Rocco Siffredi", "age": 54, "long": false },
{ "name": "Rocco Siffredi", "age": 54, "long": true },
{ "name": "John Holmes", "age": 44, "long": true },
{ "name": "Peter North", "age": 61, "long": true },
{ "name": "Rocco Siffredi", "age": 54, "long": false },
{ "name": "Rocco Siffredi", "age": 54, "long": true },
{ "name": "John Holmes", "age": 44, "long": true },
{ "name": "Peter North", "age": 61, "long": true },
{ "name": "Rocco Siffredi", "age": 54, "long": false },
{ "name": "Rocco Siffredi", "age": 54, "long": true },
{ "name": "John Holmes", "age": 44, "long": true },
{ "name": "Peter North", "age": 61, "long": true },
{ "name": "Rocco Siffredi", "age": 54, "long": false }
];
function uniqueOneliner(properties = []) {
return (item, position, list) =>
properties.some(
property =>
list.map(mapObj => mapObj[property]).indexOf(item[property]) ===
position
);
}
function unique(properties = []) {
let valuePool;
return (item, position, list) => {
// cache valuePool
if (!valuePool) {
valuePool = properties.reduce((acc, property) => {
acc[property] = list.map(mapObj => mapObj[property]);
return acc;
}, {});
}
const isDuplicate = Object.keys(valuePool).every(property => {
const candidate = item[property];
const foundIndex = valuePool[property].indexOf(candidate);
return foundIndex !== position;
});
return !isDuplicate;
};
};
Ready to run.
Test | Ops/sec | |
---|---|---|
oneliner short |
| ready |
cached short |
| ready |
oneliner long |
| ready |
cached long |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.