From 39df358fc8192cdfdfa31e8243f5ac46653127ed Mon Sep 17 00:00:00 2001 From: Eugene Lazutkin Date: Sat, 8 Jun 2024 16:26:39 -0500 Subject: [PATCH] Added a perf test to check that the caching works. * Uses `matchAll()`, which runs repeated operations on the same string. * Changing the string size should exhibit a near linear behavior. * (With high numbers we measure Node's GC and had to recreate the cache). --- tests/manual/matchall-bench.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/manual/matchall-bench.js diff --git a/tests/manual/matchall-bench.js b/tests/manual/matchall-bench.js new file mode 100644 index 0000000..4990287 --- /dev/null +++ b/tests/manual/matchall-bench.js @@ -0,0 +1,16 @@ +'use strict'; + +const RE2 = require('../../re2'); + +const N = 1_000_000; + +const s = 'a'.repeat(N), + re = new RE2('a', 'g'), + matches = s.matchAll(re); + +let n = 0; +for (const _ of matches) ++n; + +if (n !== s.length) console.log('Wrong result.'); + +console.log('Done.');