Math.max.apply vs Math.max with spread vs basic for loop vs for loop length cachingFastest: Math.max.apply (104.1x faster)
906,753 ops/sec
222,231 ops/sec
12,958 ops/sec
8,712 ops/sec
Fastest: for loop length caching (5.8x faster)
1,184,136 ops/sec
1,097,647 ops/sec
203,701 ops/sec
202,615 ops/sec
Fastest: Math.max.apply (37.4x faster)
477,035 ops/sec
318,327 ops/sec
18,431 ops/sec
12,740 ops/sec
Results show median performance across all community submissions. Run this benchmark yourself to verify on your device.
| Test case name | Result |
|---|---|
| Math.max.apply | |
| Math.max with spread | |
| basic for loop | |
| for loop length caching |
| Test name | Executions per second |
|---|---|
| ✓ for loop length caching | 1,197,844 Ops/sec |
| basic for loop | 821,205 Ops/sec |
| Math.max with spread | 288,852 Ops/sec |
| Math.max.apply | 273,224 Ops/sec |