Skip to content

Commit 5f647fb

Browse files
debadree25danielleadams
authored andcommitted
benchmark: add benchmark for EventTarget add and remove
Refs: nodejs/performance#60 PR-URL: #46779 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 89c2e8a commit 5f647fb

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
constcommon=require('../common.js');
3+
4+
constbench=common.createBenchmark(main,{
5+
n: [1e6],
6+
nListener: [5,10],
7+
});
8+
9+
functionmain({ n, nListener }){
10+
consttarget=newEventTarget();
11+
constlisteners=[];
12+
for(letk=0;k<nListener;k+=1)
13+
listeners.push(()=>{});
14+
15+
bench.start();
16+
for(leti=0;i<n;i+=1){
17+
constdummy=(i%2===0) ? 'dummy0' : 'dummy1';
18+
for(letk=listeners.length;--k>=0;){
19+
target.addEventListener(dummy,listeners[k]);
20+
}
21+
for(letk=listeners.length;--k>=0;){
22+
target.removeEventListener(dummy,listeners[k]);
23+
}
24+
}
25+
bench.end(n);
26+
}

0 commit comments

Comments
(0)