Skip to content

Commit 407992e

Browse files
avivkellermarco-ippolito
authored andcommitted
benchmark: add test_runner/mock-fn
PR-URL: #55771 Refs: #55723 Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
1 parent 83b415e commit 407992e

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

‎benchmark/test_runner/mock-fn.js‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
constassert=require('node:assert');
5+
const{ test }=require('node:test');
6+
7+
constbench=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+
constnoop=()=>{};
16+
17+
functionbenchmarkDefine(n){
18+
letnoDead;
19+
test((t)=>{
20+
bench.start();
21+
for(leti=0;i<n;i++){
22+
noDead=t.mock.fn(noop);
23+
}
24+
bench.end(n);
25+
assert.ok(noDead);
26+
});
27+
}
28+
29+
functionbenchmarkExecute(n){
30+
letnoDead;
31+
test((t)=>{
32+
constmocked=t.mock.fn(noop);
33+
bench.start();
34+
for(leti=0;i<n;i++){
35+
noDead=mocked();
36+
}
37+
bench.end(n);
38+
assert.strictEqual(noDead,noop());
39+
});
40+
}
41+
42+
functionmain({ n, mode }){
43+
if(mode==='define'){
44+
benchmarkDefine(n);
45+
}elseif(mode==='execute'){
46+
benchmarkExecute(n);
47+
}
48+
}

0 commit comments

Comments
 (0)