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 a replace all that doesn't use regex
String.prototype.replaceAll = function (needle, rep, strictMatch) {
var haystack = this, idx, len, needleE, needleR, ret;
if (haystack.length === 0) { return haystack; }
needleE = needle.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
needleR = new RegExp(needleE, strictMatch?'':'i');
ret = haystack.split(needleR).join(rep);
return ret;
};
var testString = "";
for (i=0;i<1000;i++) {
testString += "a test and crushing defeat ";
if (i%3===0) {testString += "bees suck ";}
}
var upTest = testString.toUpperCase();
Ready to run.
Test | Ops/sec | |
---|---|---|
replaceAll insensitive |
| ready |
RegExp replace all insensitive |
| ready |
replaceAll case sensitive |
| ready |
Regexp strict match replace |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.