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 doReplaceSwitch(char) {
switch(char) {
case '&':
return '&';
case '<':
return '<';
case '"':
return '"';
case '\'':
return ''';
default:
return char;
}
}
const replacementMap = {
'&': '&',
'<': '<',
'"': '"',
'\'': '''
};
function doReplaceMap(char) {
return replacementMap[char] || char;
}
function replaceSwitch(str) {
return str.replace(/[&<"']/g, doReplaceSwitch);
}
function replaceMap(str) {
return str.replace(/[&<"']/g, doReplaceMap);
}
function replaceIterateSwitch(str) {
var result = '';
for(var i = 0; i < str.length; ++i) {
var char = str[i];
result += doReplaceSwitch(char);
}
return result;
}
function replaceIterateMap(str) {
var result = '';
for(var i = 0; i < str.length; ++i) {
var char = str[i];
result += doReplaceMap(char);
}
return result;
}
function multiRegex(str) {
return str
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/"/g, '"')
.replace(/'/g, '%')
}
function doReplaceCharCode(char) {
return "&#" + char.charCodeAt(0) + ";";
}
function replaceRegexCharCode(str) {
return str.replace(/[\x26\x0A\x3c\x3e\x22\x27]/g, doReplaceCharCode);
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Regex CharCode |
| ready |
MultiRegex |
| ready |
Iterate Map |
| ready |
Iterate Switch |
| ready |
Regex Switch |
| ready |
Regex Map |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.