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
var escapeHTML1 = (function () {
var controlChars = /["'<>&]/g;
var encodedChars = {
'&': '&',
'"': '"',
'\'': ''',
'<': '<',
'>': '>'
};
function encodeChar(char) {
return encodedChars[char];
}
return function (rawTxt) {
return rawTxt.replace(controlChars, encodeChar);
};
})();
var escapeHTML2 = (function () {
var el = document.createElement('span');
el.style.display = 'none';
return function (rawTxt) {
el.appendChild(document.createTextNode(rawTxt));
return el.innerHTML;
};
})();
var testStrings = [
'<b>hello world, 1 & 2!</b>',
'this string has absolutely no html in it and does not need anything done to it.'
];
Ready to run.
Test | Ops/sec | |
---|---|---|
string replace |
| ready |
dom hijack |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.