Using indexOf vs Using lastIndexOf vs Using a SetFastest: Using a Set (5.2x faster)
742 ops/sec
169 ops/sec
142 ops/sec
Fastest: Using a Set (2.4x faster)
521 ops/sec
222 ops/sec
218 ops/sec
Results show median performance across all community submissions. Run this benchmark yourself to verify on your device.
| Test case name | Result |
|---|---|
| Using indexOf | |
| Using lastIndexOf | |
| Using a Set |
| Test name | Executions per second |
|---|---|
| ✓ Using a Set | 904 Ops/sec |
| Using indexOf | 443 Ops/sec |
| Using lastIndexOf | 289 Ops/sec |