Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Should you cache Intl.DateTimeFormat?
Testing creating a new Intl.DateTimeFormat each time vs. caching it using JSON-stringified options object as the key.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Browser:
Chrome 136
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
11 months ago
Test name
Executions per second
No caching
27334.9 Ops/sec
With JSON-keyed cache
1048662.2 Ops/sec
Script Preparation code:
FORMAT = { day: '2-digit', month: 'short', year: 'numeric' } cache = new Map()
Tests:
No caching
const date = new Intl.DateTimeFormat('en-AU', FORMAT).format(new Date())
With JSON-keyed cache
const key = JSON.stringify(FORMAT) let formatter = cache.get(key) if (!formatter) { formatter = new Intl.DateTimeFormat('en-AU', FORMAT) cache.set(key, formatter) } const date = formatter.format(new Date())