replace vs replaceAll (regex) vs replaceAll (string)Fastest: replace (1.5x faster)
13,320,794 ops/sec
10,020,734 ops/sec
8,876,506 ops/sec
Fastest: replaceAll (string) (2.1x faster)
17,907,064 ops/sec
10,111,393 ops/sec
8,660,669 ops/sec
Results show median performance across all community submissions. Run this benchmark yourself to verify on your device.
| Test case name | Result |
|---|---|
| replace | |
| replaceAll (regex) | |
| replaceAll (string) |
| Test name | Executions per second |
|---|---|
| ✓ replaceAll (string) | 10,248,375 Ops/sec |
| replace | 6,298,634 Ops/sec |
| replaceAll (regex) | 5,651,366 Ops/sec |