Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Memoized Intl.NumberFormat vs fresh instances
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/120.0.0.0 Safari/537.36 Edg/120.0.0.0
Browser:
Chrome 120
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
new Intl.NumberFormat
29132.5 Ops/sec
memoized instance
29199.2 Ops/sec
Script Preparation code:
window.cache = new Map(); window.format = (locale, currency, value) => new Intl.NumberFormat(locale, { style: 'currency', currency }).format(value); window.memoizedFormat = (locale, currency, value) => { const key = [locale, currency]; let formatter = window.cache.get(key); if (!formatter) { formatter = new Intl.NumberFormat(locale, { style: 'currency', currency }); window.cache.set(key, formatter); } return formatter.format(value); };
Tests:
new Intl.NumberFormat
window.format('pt-BR', 'BRL', 100_346_999.21);
memoized instance
window.memoizedFormat('pt-BR', 'BRL', 100_346_999.21);