Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: add test_runner/mock-fn #55771

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions benchmark/test_runner/mock-fn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict';

const common = require('../common');
const assert = require('node:assert');
const { test } = require('node:test');

const bench = common.createBenchmark(main, {
n: [1e6],
mode: ['define', 'execute'],
}, {
// We don't want to test the reporter here
flags: ['--test-reporter=./benchmark/fixtures/empty-test-reporter.js'],
});

const noop = () => {};

function benchmarkDefine(n) {
let noDead;
test((t) => {
bench.start();
for (let i = 0; i < n; i++) {
noDead = t.mock.fn(noop);
}
bench.end(n);
assert.ok(noDead);
});
}

function benchmarkExecute(n) {
let noDead;
test((t) => {
const mocked = t.mock.fn(noop);
bench.start();
for (let i = 0; i < n; i++) {
noDead = mocked();
}
bench.end(n);
assert.strictEqual(noDead, noop());
});
}

function main({ n, mode }) {
if (mode === 'define') {
benchmarkDefine(n);
} else if (mode === 'execute') {
benchmarkExecute(n);
}
}
Loading