Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Event Bubbling and Event Capturing
(version: 4)
Comparing performance of:
Delegation vs Targetting
Created:
one year ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const buttons = Array.from({length: 10000}, () => document.createElement('button')) const events = new Map() const addListener = (event, target, listener) => { let targets = events.get(event) if (targets === undefined) { targets = new Map() events.set(event, targets) } let listeners = targets.get(target) if (listeners === undefined) { listeners = new Set() targets.set(target, listeners) } listeners.add(listener) }
Tests:
Delegation
buttons.forEach((target) => { addListener('click', target, console.log) addListener('focus', target, console.log) addListener('blur', target, console.log) })
Targetting
buttons.forEach((button) => { button.addEventListener('click', console.log) button.addEventListener('focus', console.log) button.addEventListener('blur', console.log) })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Delegation
Targetting
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Delegation
2138.0 Ops/sec
Targetting
350.9 Ops/sec
Related benchmarks:
createElement
set vs compare functions and set
elementFromPoint4
getBoundingClientRect
Cost of adding and removing events
Cost of adding and removing event listeners
callback vs event
listener test
listener test1
Comments
Confirm delete:
Do you really want to delete benchmark?