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 (iPhone; CPU iPhone OS 17_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 YaBrowser/24.4.1.862.10 YaApp_iOS/2404.1 YaApp_iOS_Browser/2404.1 Safari/604.1 SA/3
Browser:
Yandex Browser 24
Operating system:
iOS 17.4.1
Device Platform:
Mobile
Date tested:
2 years ago
Test name
Executions per second
while loop + tagName check
1092.9 Ops/sec
event propagation
247.0 Ops/sec
event propagation with callback
345.8 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'); } }