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
function format(pattern, context) {
var value = '';
var i = 0;
while (true) {
var open = pattern.indexOf('{', i);
var close = pattern.indexOf('}', i);
if (open < 0 && close < 0) {
value += pattern.slice(i);
break;
} else if (close > 0 && (close < open || open < 0)) {
if (pattern.charAt(close + 1) !== '}') {
throw 'stringFormatBraceMismatch';
}
value += pattern.slice(i, close + 1);
i = close + 2;
continue;
}
value += pattern.slice(i, open);
i = open + 1;
if (value.charAt(i) === '{') {
value += '{';
i++;
continue;
} else if (close < 0) {
throw 'stringFormatBraceMismatch';
}
var name = pattern.substring(i, close);
value += context[name];
i = close + 1;
}
return value;
}
function format_r(pattern, context) {
return pattern.replace(/\{[^\}]+\}/, function(match) {
return context[match.slice(1, -1)];
});
}
Ready to run.
Test | Ops/sec | |
---|---|---|
replacing using loop |
| ready |
replacing using regular expression |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.