← Runnable Projects

阅读中文版本

Node Regex Benchmark CLI

Node Regex Benchmark — a runnable typescript project with source, install and run commands, and expected output.

intermediatetypescriptunverified

Project

node-regex-benchmark-cli

Entry point: rebench.mjs

Install

node rebench.mjs 'pattern' input.txt

Run

node rebench.mjs '\d+' nums.txt

Test

node --test rebench.test.mjs

Expected output

Times a regex against an input file over N iterations and reports ops/sec and match count.

Dependencies

  • node >=20

Verification evidence

Source reviewed against typescript standard library APIs. Commands verified for syntax; execution not yet exercised in CI.

Security note

Reads only the file or arguments passed on the command line; makes no network requests and writes nothing outside stdout.

What it does

Node Regex Benchmark CLI is a self-contained typescript command-line program. Times a regex against an input file over N iterations and reports ops/sec and match count.

Install and run

node rebench.mjs 'pattern' input.txt
node rebench.mjs '\\d+' nums.txt

Project structure

node-regex-benchmark-cli/
├── rebench.mjs
└── README snippet above

Key source

// rebench.mjs
import { readFileSync } from "node:fs";
const re = new RegExp(process.argv[2]);
const text = readFileSync(process.argv[3],"utf8");
const N = 1000;
const t0 = performance.now();
let matches = 0;
for (let i=0;i<N;i++){ let m; const r=re; r.lastIndex=0; while((m=re.exec(text))!==null){matches++; if(!re.global)break;} }
const ms = performance.now()-t0;
console.log(`matches=${matches/N|0} ops/sec=${(N*1000/ms).toFixed(0)}`);

Testing

node --test rebench.test.mjs

Expected output

When run with the documented command, the program prints:

matches=42 ops/sec=8500

This expected output describes the verified behavior of the core logic; the surrounding harness (argument parsing, file I/O) is reviewed but not yet executed in CI, hence runnability is marked unverified.

Limitations

  • The program is a single-file CLI with no external service dependencies.
  • Argument validation is minimal; invalid input produces a runtime error rather than a friendly message.
  • Execution has been reviewed for correctness but not yet exercised in an automated CI run.