Skip to content

Commit c210335

Browse files
avivkelleraduh95
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 9c99255 commit c210335

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

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+
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+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy