Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
EventTarget vs custom observable implementation
Compares browser's built-in "EventTarget" with custom similar implementation
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36
Browser:
Chrome 141
Operating system:
Windows
Device Platform:
Desktop
Date tested:
6 months ago
Test name
Executions per second
custom
5427.9 Ops/sec
native
578.5 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
class CustomTarget { constructor() { this.listeners = {}; } on(eventName, listener) { if (!(eventName in this.listeners)) { this.listeners[eventName] = new Set(); } this.listeners[eventName].add(listener); } off(eventName, listener) { this.listeners[eventName]?.delete(listener); } send(eventName, ...data) { if (!this.listeners[eventName]) { return 0; } for (let fn of this.listeners[eventName]) { fn(...data); } return this.listeners[eventName].count; } } const listeners = 10; const events = 1000; const setupCustom = () => { const target = new CustomTarget(); let total = 0; for (let i = 0; i < listeners; i++) { target.on('foo', (inc) => { total = total + inc }); } return () => { for (let i = 0; i < events; i++) { target.send('foo', 5); } } } const setupNative = () => { const target = new EventTarget(); let total = 0; for (let i = 0; i < listeners; i++) { target.addEventListener('foo', (e) => { total = total + e.detail }); } return () => { for (let i = 0; i < events; i++) { const customEvent = new CustomEvent('foo', { detail: 5 }); target.dispatchEvent(customEvent); } } } const runCustomInt = setupCustom(); const runNative = setupNative(); function runCustom() { runCustomInt(); }
Tests:
custom
runCustom();
native
runNative();