π Tempo Performance Benchmarks β
To ensure high performance in mass-instantiation scenarios, Tempo implements a "Zero-Cost Constructor" architecture using prototype shadowing and lazy delegation. This document outlines the benchmark results for these optimizations.
π Summary of Timings β
Timings were captured over 1,000 iterations to measure micro-overhead and compare different instantiation strategies.
| Method | Total Time | Β΅s / op | Notes |
|---|---|---|---|
| Default (Lazy Proxy) | 523.14ms | 523.14Β΅s | |
| Eager Simulation | 1394.51ms | 1394.51Β΅s | ~2.7x slower (simulating pre-refactor impact). |
| Fast-Fail @sync | 359.04ms | 359.04Β΅s | Rejected instantly by the Master Guard. |
| Object.create Baseline | 0.22ms | 0.22Β΅s | Raw JS overhead for comparison. |
ποΈ Architectural Impact β
1. Proxy-Delegator Delegation ( ) β
By using a Proxy-Delegator pattern, the constructor returns near-instantly without populating the formatting (fmt) or Term (term) objects. These registries are only discovered and memoized on the first property access.
- Gain: ~65% reduction in instantiation overhead.
- v2.1.2 Update: The Scan-and-Consume guard further stabilizes the "Zero-Cost Constructor" by ensuring that even with massive plugin lists, the entry-point remains
.
2. The Master Guard (Fast-Fail) β
The dynamic Master Guard acts as a rapid scan-and-consume gatekeeper.
- Efficiency: Invalid inputs are rapidly rejected via a fast greedy scan, bounding failure costs tightly to string length.
- Performance: Validating a string against the guard is ~30% faster than a full parsing cycle, even for simple ISO strings.
π§ͺ Benchmark Methodology β
The benchmark script used performance.now() within a Vitest environment to ensure accurate module resolution and test environment isolation.
- Lazy Creation: Creates a
new Tempo('2024-05-20')without accessing any properties. - Eager Simulation: Creates a
new Tempo()and manually triggers discovery on 5 core properties to simulateinitialization. - Invalid Parse: Passes a string that fails the Master Guard (e.g., includes emojis or exotic symbols) to measure rejection speed.
INFO
These benchmarks represent the library's performance under Node.js v22+. Results may vary based on the JS engine (V8, JavaScriptCore, etc.) but the
π Self-Service Benchmark Module β
Tempo provides a built-in BenchmarkModule to allow developers to prove the performance ROI in their own exact environment (e.g. comparing Node.js memory metrics against Browser DOM performance).
This module is completely decoupled from the core to keep the bundle light, but accepts your specific configured Tempo instance to give accurate results.
Usage β
import { Tempo } from 'tempo-kit';
import { BenchmarkModule } from 'tempo-kit/module/benchmark';
// 1. Configure your Tempo instance (e.g. plugins, timezone, etc)
Tempo.init({ timeZone: 'America/New_York' });
// 2. Run the benchmark against your datasets
const results = BenchmarkModule.run(Tempo, {
data: ['2026-05-20', '2026-05-21', 'Invalid-Pizza-String'], // production datasets
iterations: 100, // stress-test count
baseline: true, // compare against native `new Date()`
modes: ['auto', 'defer']
});
console.table(results);Metrics Collected β
The BenchmarkModule is platform-aware. Using the internal getContext() utility, it tracks:
totalTimeMs: Total elapsed time using high-resolution timers (performance.now()).microSecPerOp: The average number of microseconds (Β΅s) taken per operation.successRate: The percentage of strings that successfully resolved to a valid date.heapUsedDeltaMb: (Node.js Only) The change in memory allocation to measure Garbage Collection overhead and memory safety.
Indicative Benchmark Results (v5.0.0) β
When evaluated with bench.v5.0.0.ts (--expose-gc + per-mode warm-up) against a 20-entry mixed corpus (Strict ISO, compact numeric shorthands, relative expressions like next Friday at 5pm and in 3 weeks, and epoch timestamps) over 2,000 operations (100 iterations Γ 20 inputs) on Node.js v26.10.0, BenchmarkModule yields:
| Strategy | Β΅s / Op | Total Time | Success Rate | Memory Overhead | Notes |
|---|---|---|---|---|---|
| Native Date | 0.18 Β΅s | 0.36 ms | 25.0% | 0.23 MB | Raw C++ speed, but fails on 1,500/2,000 shorthand, relative, and natural-language inputs. |
| Tempo (Auto) | 957.59 Β΅s | 1,915.19 ms | 100.0% | 70.01 MB | Sub-millisecond full natural-language, shorthand, and localized parsing (~2.32Γ faster than v4.4.3). |
| Tempo (Defer) | 946.40 Β΅s | 1,892.80 ms | 100.0% | 65.30 MB | Fastest overall: defers deep eager discovery until accessed (~2.28Γ faster than v4.4.3). |
| Tempo (Strict) | 1,076.69 Β΅s | 2,153.38 ms | 100.0% | 105.16 MB | ~2.08Γ faster than v4.4.3; bypasses heuristic fallback attempts. |
Additional v5.0.0 Throughput Profiles β
- Stock Baseline (
WeakCache, 20-entrybaseCorpusΓ 100 iterations = 2,000 ops):1,030.68 Β΅s / op(970 ops/sec,100.0%success rate). - Repeated ISO Memoization (
WeakCache, 4-entryrepeatCorpusΓ 500 iterations = 2,000 ops):1,042.82 Β΅s / op(959 ops/sec,100.0%success rate). - Localized
fr-FRModifiers (8-entryfrCorpusΓ 100 iterations = 800 ops):1,292.63 Β΅s / op(774 ops/sec,100.0%success rate).
π Key Takeaways β
- Sub-Millisecond Rich Parsing: Native
Dateis fast (0.18 Β΅s) on strict ISO/RFC strings, but fails75%of the mixed corpus (25.0%success). Tempo resolves 100.0% of the corpus at ~0.95 ms / op inautoanddefermodes. - 2Γ+ Throughput Improvement Over
v4.4.3: Compared against the committedv4.4.3benchmark artifact (v4.4.3time Γ·v5.0.0time),v5.0.0records 2.08Γβ2.36Γ lower per-operation timings across the three corpora (baseCorpus20Γ100,repeatCorpus4Γ500, andfrCorpus8Γ100). Note that thev5.0.0BenchmarkModuleharness adds a per-mode warm-up loop and a pre-timinggc()call (--expose-gc) not present in thev4.4.3run, so part of theauto/defer/strictreduction reflects cleaner warm-up/GC isolation in addition to engine gains. - Adapt This Test: The runner script used to generate these results is available in the
bench/runner.test.tsdirectory. You can use it as a scaffold to test Tempo against your own unique datasets.