From 4078aa83ff3ddfe5a6c5ccd2e1279c923ce10cfa Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Tue, 3 Sep 2024 11:50:34 -0300 Subject: [PATCH] benchmark: add match and doesNotMatch bench PR-URL: https://github.com/nodejs/node/pull/54734 Reviewed-By: Rich Trott Reviewed-By: Chemi Atlow --- benchmark/assert/match.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 benchmark/assert/match.js diff --git a/benchmark/assert/match.js b/benchmark/assert/match.js new file mode 100644 index 00000000000000..fab86a23944c59 --- /dev/null +++ b/benchmark/assert/match.js @@ -0,0 +1,21 @@ +'use strict'; + +const common = require('../common.js'); +const assert = require('assert'); + +const bench = common.createBenchmark(main, { + n: [25, 2e7], + method: ['match', 'doesNotMatch'], +}); + +function main({ n, method }) { + const fn = assert[method]; + const actual = 'Example of string that will match'; + const expected = method === 'match' ? /will match/ : /will not match/; + + bench.start(); + for (let i = 0; i < n; ++i) { + fn(actual, expected); + } + bench.end(n); +}