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
how to apply a map of string translations 'foofoobar' + { 'foo': 'bar', 'baz': 'qux' } = 'barbarbar'
var src = 'fooforbar';
var map = { 'foo': 'bar', 'baz': 'qux' };
var expected = 'barbarbar';
function replace_loop(src, map) {
var ret = src;
for (var k in map)
ret = ret.replace(k, map[k]);
return ret;
}
function replace_fun(src, map) {
var r = new RegExp('(' + Object.keys(map).join('|') + ')', 'igm');
return src.replace(r, function(k) {
return map[k];
});
}
Ready to run.
Test | Ops/sec | |
---|---|---|
replace_loop |
| ready |
replace_fun |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.