Skip to content

๐Ÿš€ 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.

MethodTotal Timeยตs / opNotes
Default (Lazy Proxy)523.14ms523.14ยตsCurrent O(1) constructor.
Eager Simulation1394.51ms1394.51ยตs~2.7x slower (simulating pre-refactor impact).
Fast-Fail @sync359.04ms359.04ยตsRejected instantly by the Master Guard.
Object.create Baseline0.22ms0.22ยตsRaw JS overhead for comparison.

๐Ÿ—๏ธ Architectural Impact โ€‹

1. Proxy-Delegator Delegation (O(1)) โ€‹

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 O(1).

2. The Master Guard (Fast-Fail) โ€‹

The static #guard regex acts as a rapid "Sync Point."

  • Efficiency: Strings that do not contain valid date-time characters are rejected in O(1) time.
  • 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 internal alias support (#library).

  1. Lazy Creation: Creates a new Tempo('2024-05-20') without accessing any properties.
  2. Eager Simulation: Creates a new Tempo() and manually triggers discovery on 5 core properties to simulate O(N) initialization.
  3. 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 O(1) complexity remains constant.

Released under the MIT License.