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
const DELIMITER = " ";
const myString = " Hello this is my World ";
function splitIntoWords(string) {
const words = [];
let buffer = "";
for (let i = 0; i < string.length; i++) {
const char = string[i];
if (char !== DELIMITER) {
while (i < string.length && string[i] !== DELIMITER) {
buffer += string[i];
i++;
}
words.push(buffer);
buffer = "";
}
}
return words;
}
function splitIntoWords2(string) {
const words = [];
let buffer = "";
for (let i = 0; i < string.length; i++) {
const char = string[i];
if (char !== DELIMITER) {
buffer += char;
} else if (buffer.length > 0) {
words.push(buffer);
buffer = "";
}
}
return words;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Trim + Replace + Split |
| ready |
splitIntoWords |
| ready |
splitIntoWords2 |
| ready |
Trim + Split + Filter |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.