-
-
Notifications
You must be signed in to change notification settings - Fork 53
Benchmarks
The bench/ directory contains micro-benchmarks using nano-benchmark. They compare related components on generated datasets.
npm run bench -- bench/parser-jsonc.mjs
npm run bench -- bench/parser-jsonl.mjs
npm run bench -- bench/assembler-flex.mjsUse nano-bench options after --: npm run bench -- bench/parser-jsonc.mjs --ms 200 --samples 50. Run npx nano-bench --help for details.
File: bench/parser-jsonc.mjs
Compares Parser and jsonc/Parser on the same ~100 KB JSON array. Both process identical input through chain() pipelines, measuring overhead of JSONC comment/trailing-comma support on plain JSON.
Typical result: no statistically significant difference. The JSONC parser's additional regex branches for //, /*, and trailing commas add negligible overhead when comments are absent.
Takeaway: use jsonc/Parser freely when input might contain comments — there is no measurable penalty on standard JSON.
File: bench/parser-jsonl.mjs
Compares two ways to process JSONL (one JSON value per line):
-
parser({jsonStreaming: true})+streamValues()— streaming tokenizer + assembler. -
jsonl/Parser— line splitter + nativeJSON.parse().
Typical result: jsonl/Parser is ~10× faster.
Takeaway: for strict JSONL/NDJSON input where individual items fit in memory, always prefer jsonl/Parser. Use the streaming parser only when you need token-level access or when items are too large to parse in one shot. See also Performance § JSONL.
File: bench/assembler-flex.mjs
Feeds a pre-generated token array (~500 objects, ~10 000 tokens) to Assembler and FlexAssembler via consume(). Three variants:
| Variant | Description |
|---|---|
assembler |
Standard Assembler — baseline. |
flex-assembler |
FlexAssembler with no rules — measures structural overhead. |
flex-assembler (Map rules) |
FlexAssembler with an always-matching object rule creating Maps. |
Typical result: FlexAssembler (no rules) is ~8% slower than Assembler. With an always-matching Map rule, ~15% slower.
Takeaway: for plain object assembly, Assembler is slightly faster. FlexAssembler overhead is modest and scales with the number of rules that need to be checked. Use it when you need custom containers; otherwise prefer Assembler.
All benchmarks generate data on the fly at import time — no large files are committed. Each file creates a ~50–100 KB payload of synthetic objects with mixed types (strings, numbers, booleans, arrays, nested objects).
Start here
Core
Filters
Streamers
Essentials
Utilities
File I/O (Node-only)
JSONC
JSONL (use stream-chain)
Reference
Built on stream-chain