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
Based on http://jsperf.com/tnadler/3 to investigate the cost components of creating a Custom Element and creating a Shadow Root.
<template id="small-template">
<div>Hello!</div>
</template>
<script>
var registerComponentTemplate = function(id, componentName) {
var tpl = document.getElementById(id);
var obj = Object.create(HTMLElement.prototype, {});
obj.createdCallback = function() {
var root = this.createShadowRoot();
root.appendChild(document.importNode(tpl.content));
}
document.register(componentName, {'prototype': obj});
}
var registerComponentInnerWithShadow = function(str, componentName) {
var obj = Object.create(HTMLElement.prototype, {});
obj.createdCallback = function() {
var root = this.createShadowRoot();
root.innerHTML = str;
}
document.register(componentName, {'prototype': obj});
}
var registerComponentInnerWithoutShadow = function(str, componentName) {
var obj = Object.create(HTMLElement.prototype, {});
obj.createdCallback = function() {
this.innerHTML = str;
}
document.register(componentName, {'prototype': obj});
}
registerComponentTemplate('small-template', 'small-template');
registerComponentInnerWithShadow('Hello!', 'small-inner-shadow');
registerComponentInnerWithoutShadow('Hello!', 'small-inner');
</script>
window.victim = document.createElement('div');
document.body.appendChild(victim);
victim.remove();
Ready to run.
Test | Ops/sec | |
---|---|---|
Regular Small |
| ready |
With Shadow Root |
| ready |
Custom Element w/ innerHTML |
| ready |
Custom Element w/ ShadowRoot and innerHTML |
| ready |
Custom Element w/ ShadowRoot and Template |
| ready |
Call innerHTML twice |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.