Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Getting a context: while loop vs event propagation with new events vs event propagation with callbacks
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Browser:
Chrome 127
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
while loop + tagName check
646.5 Ops/sec
event propagation
205.5 Ops/sec
event propagation with callback
338.9 Ops/sec
HTML Preparation code:
<context-provider id="provider"> <div> <div></div> <div></div> <div></div> <div></div> <div> <div> <span> <span> <span>abc</span> </span> def <span> <span id="foo"></span> </span> </span> </div> ghi </div> </div> </context-provider>
Script Preparation code:
var context = document.getElementById('provider'); var element = document.getElementById('foo'); var SimpleContextEvent = class SimpleContextEvent extends Event { data = null; callback = null; constructor(callback) { super('context-request', {bubbles: true, composed: true}); this.callback = callback; } }; context.addEventListener('context-request', event => { if (event.callback) { event.callback(context); } else { event.data = context; } event.stopPropagation(); });
Tests:
while loop + tagName check
var i = 5000; while (i--) { let ctx = element; while (ctx && ctx.nodeName !== 'CONTEXT-PROVIDER') { ctx = ctx.assignedSlot || ctx.parentNode || ctx.host; } if (ctx !== context) { throw new Error('mismatch'); } }
event propagation
var i = 5000; while (i--) { let ctxEvent = new SimpleContextEvent(); element.dispatchEvent(ctxEvent); let ctx = ctxEvent.data; if (ctx !== context) { throw new Error('mismatch'); } }
event propagation with callback
var i = 5000; var ctx; var ctxEvent = new SimpleContextEvent(reply => {ctx = reply;}); while (i--) { ctx = null; element.dispatchEvent(ctxEvent); if (ctx !== context) { throw new Error('mismatch'); } }