Intl.NumberFormat caching (v2)

Revision 2 of this benchmark created on


Setup

const formattersJson = {};
const options = { style: 'currency', currency: 'USD' };
const isoLocale = 'en-UK';
const amount = 100;

Test runner

Ready to run.

Testing in
TestOps/sec
Control
const numberFormat = new Intl.NumberFormat(isoLocale, options);

numberFormat.formatToParts(amount);
ready
Cache 1
const key = isoLocale + JSON.stringify(options);
 
if(!(key in formattersJson)){
 	formattersJson[key] = new Intl.NumberFormat(isoLocale, options);
 }
 
formattersJson[key].formatToParts(amount);

ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.