Commit e47544a 1 parent 6397055 commit e47544a Copy full SHA for e47544a
File tree 1 file changed +48
-0
lines changed
1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const common = require ( '../common' ) ;
4
+ const assert = require ( 'node:assert' ) ;
5
+ const { test } = require ( 'node:test' ) ;
6
+
7
+ const bench = common . createBenchmark ( main , {
8
+ n : [ 1e6 ] ,
9
+ mode : [ 'define' , 'execute' ] ,
10
+ } , {
11
+ // We don't want to test the reporter here
12
+ flags : [ '--test-reporter=./benchmark/fixtures/empty-test-reporter.js' ] ,
13
+ } ) ;
14
+
15
+ const noop = ( ) => { } ;
16
+
17
+ function benchmarkDefine ( n ) {
18
+ let noDead ;
19
+ test ( ( t ) => {
20
+ bench . start ( ) ;
21
+ for ( let i = 0 ; i < n ; i ++ ) {
22
+ noDead = t . mock . fn ( noop ) ;
23
+ }
24
+ bench . end ( n ) ;
25
+ assert . ok ( noDead ) ;
26
+ } ) ;
27
+ }
28
+
29
+ function benchmarkExecute ( n ) {
30
+ let noDead ;
31
+ test ( ( t ) => {
32
+ const mocked = t . mock . fn ( noop ) ;
33
+ bench . start ( ) ;
34
+ for ( let i = 0 ; i < n ; i ++ ) {
35
+ noDead = mocked ( ) ;
36
+ }
37
+ bench . end ( n ) ;
38
+ assert . strictEqual ( noDead , noop ( ) ) ;
39
+ } ) ;
40
+ }
41
+
42
+ function main ( { n, mode } ) {
43
+ if ( mode === 'define' ) {
44
+ benchmarkDefine ( n ) ;
45
+ } else if ( mode === 'execute' ) {
46
+ benchmarkExecute ( n ) ;
47
+ }
48
+ }
You can’t perform that action at this time.
0 commit comments