toFixed(4) vs toPrecision(4).toString() vs (Math.round(*10000)/10000).toString()Fastest: (Math.round(*10000)/10000).toString() (1.2x faster)
7,703,244 ops/sec
7,188,518 ops/sec
6,580,609 ops/sec
Fastest: (Math.round(*10000)/10000).toString() (79.1x faster)
945,572,032 ops/sec
17,930,714 ops/sec
11,959,754 ops/sec
Results show median performance across all community submissions. Run this benchmark yourself to verify on your device.
| Test case name | Result |
|---|---|
| toFixed(4) | |
| toPrecision(4).toString() | |
| (Math.round(*10000)/10000).toString() |
| Test name | Executions per second |
|---|---|
| ✓ (Math.round(*10000)/10000).toString() | 2,195,602,176 Ops/sec |
| toFixed(4) | 20,338,112 Ops/sec |
| toPrecision(4).toString() | 19,812,680 Ops/sec |