Investigate a slow pattern
Compare two patterns against the same inputs, then repeat the measurement in Node.js.
Reduce the problem
- Select the same engine as your application.
- Keep the pattern and flags that reproduce the delay.
- Replace sensitive input with synthetic text that retains the relevant structure.
- Reduce the input while preserving the symptom.
If a pattern stalls the editor, stop the operation and reduce the input before trying again. A timeout stops execution after the configured limit.
Compare two equivalent bounded patterns
These JavaScript patterns recognize the same four-digit identifier format. Use no flags:
^ORD-[0-9][0-9][0-9][0-9]$
^ORD-[0-9]{4}$
Use the same cases for both:
ORD-0042
ORD-9999
ORD-42
XORD-0001
First verify their matching results. Both accept the first two values and reject the last two.
Measure under comparable conditions
The benchmark tool is available with Pro. Use the same engine, flags, cases, and measurement configuration for each candidate. Keep the browser and machine conditions as stable as practical.
Record the engine, browser version, machine, input sizes, repeated measurements, and any timeout or error. Repeat a run before drawing a conclusion from a small timing difference. Keep successful inputs separate from nearly matching inputs that fail late.
Verify in the target runtime
This script measures the matching loops in Node.js. It prints observations from your machine, without an expected timing result.
import { performance } from 'node:perf_hooks'
const cases = ['ORD-0042', 'ORD-9999', 'ORD-42', 'XORD-0001']
const patterns = [/^ORD-[0-9][0-9][0-9][0-9]$/, /^ORD-[0-9]{4}$/]
for (const pattern of patterns) {
for (let warmup = 0; warmup < 10000; warmup++) {
for (const input of cases) pattern.test(input)
}
const samples = []
for (let repeat = 0; repeat < 5; repeat++) {
const start = performance.now()
for (let iteration = 0; iteration < 10000; iteration++) {
for (const input of cases) pattern.test(input)
}
samples.push(performance.now() - start)
}
console.log(pattern.source, samples)
}
Save this as an .mjs file and run it with Node.js.
The measurements include loop overhead. They exclude compilation because the patterns are created before the loop.
Interpret the result
Selected test inputs cannot establish the worst possible input or prove protection against regex denial of service. A production assessment also needs input-size limits, runtime limits, and representative traffic. If timing differences are small or inconsistent, the measurements do not support a speed claim for either pattern.