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>
function safe_tags_regex(str) {
return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
}
var div1 = document.createElement('div');
function safe_tags_dom(str) {
if(div1.childNodes.length){
div1.removeChild(div1.childNodes[0]);
}
div1.appendChild(document.createTextNode(str));
return div1.innerHTML;
}
var div2 = document.createElement('div');
function safe_tags_dom2(str) {
div2.innerText = str;
return div2.innerHTML;
}
var tagsToReplace = {
'&': '&',
'<': '<',
'>': '>'
};
function replaceTag(tag) {
return tagsToReplace[tag] || tag;
}
function safe_tags_replace(str) {
return str.replace(/[&<>]/g, replaceTag);
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Using Regular Expression |
| ready |
Using DOM textNode |
| ready |
Using replace |
| ready |
Using DOM innerText |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.