toLocaleString vs Intl.NumberFormat.format

Benchmark created on


Description

According to MDN, toLocaleString has to run a lookup each time its called. In cases where its called many times, it's better to create a Intl.NumberFormat object and use its format method. This tests that claim.

Setup

const formatter = new Intl.NumberFormat('en-US')

Test runner

Ready to run.

Testing in
TestOps/sec
toLocaleString
(10e6).toLocaleString('en-US')
ready
Intl.NumberFormat.format
formatter.format(10e6)
ready

Revisions

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