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
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
var html = document.body.innerHTML;
var map = {
"&": "&",
"'": "'",
'"': """,
"<": "<",
">": ">"
};
var tempJqElement = $(document.createElement("div"));
var tempElement = document.createElement("div");
function replace_with_switch(c) {
switch (c) {
case "&":
return "&";
case "'":
return "'";
case '"':
return """;
case "<":
return "<";
case ">":
return ">";
}
}
function replace_with_map(c) {
return map[c];
}
function replace_charcode(c) {
return '&#'+c.charCodeAt(0)+';';
}
var re_all = /[&"'\<\>]/g;
var re_amp = /&/g;
var re_quot = /"/g;
var re_apos = /'/g;
var re_lt = /</g;
var re_gt = />/g;
var re_arr = [
[re_amp, '&'],
[re_quot, '"'],
[re_apos, '''],
[re_lt, '<'],
[re_gt, '>']
];
var encodeCustom=function(input){
if (!input){
return input;
}
var out=[];
var slice=-1;
for (var i=0;i<input.length;++i){
var code=input.charCodeAt(i);
if (code>127){
out.push(input.slice(slice+1,i));
out.push('&#'+code+';');
slice=i;continue;;
}
switch (input.charCodeAt(i)){
case 38:
out.push(input.slice(slice+1,i));
out.push('&');
slice=i;
break;
case 39:
out.push(input.slice(slice+1,i));
out.push(''');
slice=i;
case 34:
out.push(input.slice(slice+1,i));
out.push('"e;');
slice=i;
break;
case 60:
out.push(input.slice(slice+1,i));
out.push('<');
slice=i;
break;
case 62:
out.push(input.slice(slice+1,i));
out.push('>');
slice=i;
break;
}
}
if (slice<input.length){
out.push(input.slice(slice+1));
}
return out.join('');
};
Ready to run.
Test | Ops/sec | |
---|---|---|
multiple replace() |
| ready |
single replace with map |
| ready |
single replace with switch |
| ready |
createTextNode |
| ready |
use jQuery with pre-created element |
| ready |
using textContent/innerText with precreated element |
| ready |
new Option |
| ready |
createTextNode with precreated element |
| ready |
multiple replace using array |
| ready |
convert to charCode entities |
| ready |
Split and join |
| ready |
.replace |
| ready |
jquery |
| ready |
custom |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.