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, '>');
}
function safe_tags_dom(str) {
var div = document.createElement('div');
div.appendChild(document.createTextNode(str));
return div.innerHTML;
}
function safe_tags_dom2(str) {
var div = document.createElement('div');
div.innerText = str;
return div.innerHTML;
}
var textarea = document.createElement('textarea');
function safe_tags_textarea(str) {
textarea.innerHTML=str;
return textarea.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 textarea |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.