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
testing 2 approaches:
the functon should always returns an empty string for the secnd returned value.
<script>
function splitByFirstComma1(str) {
const firstCommaPos = str.indexOf(',');
if (firstCommaPos === -1) {
return [str, ""];
}
const firstPart = str.substr(0, firstCommaPos);
const lastPart = str.substr(firstCommaPos+1);
console.log(">", firstPart, lastPart);
return [firstPart, lastPart];
}
function splitByFirstComma2(str) {
const [firstPart, ...rest] = str.split(",");
return [firstPart, rest.join(",")]
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
split1 no comma |
| ready |
split1 with 2 parts |
| ready |
split1 lot of commas |
| ready |
split2 with no comma |
| ready |
split2 with 2 parts |
| ready |
split2 lot of commas |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.