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
Array .includes vs object lookup. 300 items and value of 20 characters length.
var AMOUNT_OF_VALUES = 300;
var STRING_VALUE_LENGTH = 20;
function generateRandomString() {
return 'x'.repeat(STRING_VALUE_LENGTH).replace(/[x]/g, function (c) {
var r = Math.random() * 16 | 0;
var v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
var valuesArray = [...Array(AMOUNT_OF_VALUES)].map(_ => generateRandomString());
var valuesObject = valuesArray.reduce((acc, e) => ({ ...acc, [e]: true }), {});
var getRandomValue = () => valuesArray[Math.floor(Math.random() * valuesArray.length)];
Ready to run.
Test | Ops/sec | |
---|---|---|
.includes |
| ready |
object lookup |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.