toFixed(4) vs toPrecision(4).toString() vs (Math.round(*10000)/10000).toString() vs Math.floor fastFastest: Math.floor fast (3.8x faster)
20,055,864 ops/sec
7,626,493 ops/sec
7,088,945 ops/sec
5,237,924 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() | |
| Math.floor fast |
| Test name | Executions per second |
|---|---|
| ✓ Math.floor fast | 68,666,472 Ops/sec |
| (Math.round(*10000)/10000).toString() | 67,501,424 Ops/sec |
| toPrecision(4).toString() | 8,061,111 Ops/sec |
| toFixed(4) | 4,404,910 Ops/sec |