Skip to content

Commit

Permalink
Added a perf test to check that the caching works.
Browse files Browse the repository at this point in the history
* 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).
  • Loading branch information
uhop committed Jun 8, 2024
1 parent 55f6c37 commit 39df358
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/manual/matchall-bench.js
Original file line number Diff line number Diff line change
@@ -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.');

0 comments on commit 39df358

Please sign in to comment.