You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This benchmark explores various techniques available in Node.js for efficiently finding patterns within a file.
Benchmark Requirements
File matching: The method should be able to match files based on a glob pattern.
Each File: The method should search for the pattern within each file.
Multiple Matches: The method must be able to capture multiple matches in the content, if present.
Bailout: The method should be able to stop searching within a file after the first match if the bail flag is set to true.
Result Format: The method should return an array of hits, it is possible to derive the following information from each hit:
📄 File Path: The path to the file containing the pattern.
📏 Start Line: The starting line of the pattern within the content.
📍 Start Column: The starting position (column) of the pattern within the content.
📏 (optional) End Line: The ending line of the pattern within the content.
📍 (optional) End Column: The ending position (column) of the pattern within the content.
Potential result shape:
/** * Represents the position of a pattern within a line. */exporttypeSourcePosition={startLine: number;endLine?: number;startColumn: number;endColumn?: number;};/** * Represents the location of a pattern within a file. */exporttypeSourceLocation={/** * The path to the file containing the pattern. */file: string,/** * The position of the search pattern within the file. */position: SourcePosition};
The sync generator + dir regex benchmark is the fastest.
clk: ~3.36 GHz
cpu: Apple M2 Max
runtime: node 23.9.0 (arm64-darwin)
benchmark avg (min … max) p75 / p99 (min … top 1%)
------------------------------------------- -------------------------------
• dir-0-file-10000-nest-0-loc-1000-l-400; count: 10000; glob: **/file_[0-9]*.txt
------------------------------------------- -------------------------------
sync generator + dir globby 2.63 s/iter 2.47 s 2.54 s ▃▁▁▆▃█▁▃▁▁▃
sync generator + dir regex 2.44 s/iter 2.45 s 2.47 s ▃▁▃▁▁▁█▅▃▃▃
async generator + dir regex 2.50 s/iter 2.51 s 2.52 s ▃▁▁█▃▃▃▁▃▆▃
summary
sync generator + dir regex
1.02x faster than async generator + dir regex
1.08x faster than sync generator + dir globby
• dir-0-file-1000-nest-0-loc-1000-l-400; count: 1000; glob: **/file_[0-9]*.txt
------------------------------------------- -------------------------------
sync generator + dir globby 242.63 ms/iter 244.25 ms 246.80 ms ▃▁▃▃▁█▆▃▃▁▃
sync generator + dir regex 242.00 ms/iter 243.43 ms 244.89 ms ▃▆▁█▃▁▁▆▁▃▃
async generator + dir regex 244.29 ms/iter 244.55 ms 247.90 ms ▃▁▆▃█▃▆▁▁▁▃
summary
sync generator + dir regex
1x faster than sync generator + dir globby
1.01x faster than async generator + dir regex
• dir-0-file-100-nest-0-loc-1000-l-400; count: 100; glob: **/file_[0-9]*.txt
------------------------------------------- -------------------------------
sync generator + dir globby 24.47 ms/iter 24.86 ms 25.75 ms ▂▁▂▄▅▄█▅▄▃▂
sync generator + dir regex 24.55 ms/iter 25.21 ms 25.91 ms ▄▄▃▄▅█▇▄▇▄▃
async generator + dir regex 25.40 ms/iter 25.87 ms 26.30 ms ▄█▄▄█▂▆▅▅▆▃
summary
sync generator + dir globby
1x faster than sync generator + dir regex
1.04x faster than async generator + dir regex
• dir-0-file-10-nest-0-loc-1000-l-400; count: 10; glob: **/file_[0-9]*.txt
------------------------------------------- -------------------------------
sync generator + dir globby 2.78 ms/iter 2.86 ms 3.18 ms ▁▃▅██▇▅▃▂▂▁
sync generator + dir regex 2.34 ms/iter 2.37 ms 2.65 ms ▃▅█▇▆▃▂▁▁▁▁
async generator + dir regex 2.54 ms/iter 2.66 ms 2.85 ms ▃▅▄▄▆▅█▆▆▄▂
summary
sync generator + dir regex
1.09x faster than async generator + dir regex
1.19x faster than sync generator + dir globby
• dir-3-file-10-nest-3-loc-1000-l-400; count: 1180; glob: **/file_[0-9]*.txt
------------------------------------------- -------------------------------
sync generator + dir globby 99.75 ms/iter 100.06 ms 100.36 ms ▅▁▁▅▅▁▅▅█▅▅
sync generator + dir regex 98.01 ms/iter 99.12 ms 99.89 ms █▁▁█▁▅▁▅▅▅▅
async generator + dir regex 103.67 ms/iter 104.53 ms 104.88 ms ▅█▁▅▁▁█▁▁█▅
summary
sync generator + dir regex
1.02x faster than sync generator + dir globby
1.06x faster than async generator + dir regex
• dir-3-file-10-nest-6-loc-1000-l-400; count: 32770; glob: **/file_[0-9]*.txt
------------------------------------------- -------------------------------
sync generator + dir globby 3.13 s/iter 2.79 s 4.46 s █▃▁▁▁▁▁▁▁▁▂
sync generator + dir regex 2.76 s/iter 2.77 s 2.79 s ▃▁▆▃▃█▃▃▁▁▃
async generator + dir regex 2.83 s/iter 2.85 s 2.88 s ▅▅▅▅▅▅▁▅█▅▅
summary
sync generator + dir regex
1.03x faster than async generator + dir regex
1.13x faster than sync generator + dir globby