mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
2d63dee446
PR-URL: https://github.com/nodejs/node/pull/55771 Refs: https://github.com/nodejs/node/issues/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>
49 lines
967 B
JavaScript
49 lines
967 B
JavaScript
'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);
|
|
}
|
|
}
|