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
if (!window.setupDefined) {
window.setupDefined = true;
window.gen_str = function (count) {
var result = '',
alpha = 'zxcvbnm,./\\\';lkjhgfdsaqwertyuiop[]<>?|":}{+_)(*&^%$#@!~`1234567890-=';
while (result.length < count) {
result = result.concat(Math.random().toString(36).slice(2));
}
result = result.slice(result.length - count);
return result;
};
window.gen_str2 = function (count) {
var result = '',
alpha = 'zxcvbnm,./\\\';lkjhgfdsaqwertyuiop[]<>?|":}{+_)(*&^%$#@!~`1234567890-=',
i;
for (i = 0; i < count; i += 1) {
result = result.concat(alpha[Math.floor(Math.random() * alpha.length)]);
}
return result;
};
window.get_timer = function (sstart) {
var tstart = (new Date()).getTime();
return function (send) {
console.log(sstart + ((new Date()).getTime() - tstart) / 1000 + send);
};
};
window.count_split = function (str, schar) {
return str.split(schar).length - 1;
};
window.count_for = function (str,schar) {
var count = 0,
i;
for (i = 0; i < str.length; i += 1) {
if(str[i] === schar) {
count += 1;
}
}
return count;
};
window.count_replace = function (str, schar) {
return str.length - str.replace(RegExp(schar), '').length;
};
window.count_match = function (str, schar) {
return str.match(RegExp(schar, 'g')).length;
};
window.stringToTest = gen_str(1 * 1000 * 1000);
} // End-of: if (!window.setupDefined) {
Ready to run.
Test | Ops/sec | |
---|---|---|
count_split |
| ready |
count_for |
| ready |
count_replace |
| ready |
count_match |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.