HTML Preparation code:
AخA
 
1
<!--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();
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    custom
    native

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 15 days ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Chrome 134 on Windows
View result in a separate tab
Test name Executions per second
custom 7805.9 Ops/sec
native 248.8 Ops/sec