substring and substring vs replace inline regex vs replace compiled regex var vs brackets and substring vs brackets and slice vs substring and slice vs brackets and substr (legacy) vs substr and substr (legacy)Fastest: replace inline regex (1.3x faster)
6,888,864 ops/sec
6,306,034 ops/sec
6,284,784 ops/sec
6,273,526 ops/sec
6,262,888 ops/sec
6,245,935 ops/sec
6,201,074 ops/sec
5,189,778 ops/sec
Results show median performance across all community submissions. Run this benchmark yourself to verify on your device.
| Test case name | Result |
|---|---|
| substring and substring | |
| replace inline regex | |
| replace compiled regex var | |
| brackets and substring | |
| brackets and slice | |
| substring and slice | |
| brackets and substr (legacy) | |
| substr and substr (legacy) |
| Test name | Executions per second |
|---|---|
| ✓ brackets and substring | 9,635,666 Ops/sec |
| substring and slice | 9,036,284 Ops/sec |
| substring and substring | 8,957,487 Ops/sec |
| brackets and substr (legacy) | 8,950,256 Ops/sec |
| brackets and slice | 8,878,268 Ops/sec |
| substr and substr (legacy) | 8,680,502 Ops/sec |
| replace compiled regex var | 6,666,793 Ops/sec |
| replace inline regex | 6,367,285 Ops/sec |