Very much seems like a compiler edge case. Here a benchy benchmark:
import benchy
proc reverse(s: string): string =
result = s
let size = s.len
for (i, c) in s.pairs():
result[(size - i - 1)] = c
let s = "Hello world"
timeIt "With Discard":
discard reverse(s)
for i in 1..200_000:
let x = s.reverse()
keep(x)
timeIt "No Discard":
for i in 1..200_000:
let x = s.reverse()
keep(x)
Run
min time avg time std dv runs name
44.975 ms 47.967 ms ±1.599 x104 With Discard
45.317 ms 48.030 ms ±1.566 x104 No Discard
Run
- Why is My Nim Code Faster when Doing This walkr
- Why is My Nim Code Faster when Doing This treeform
- Why is My Nim Code Faster when Doing This treeform
- Why is My Nim Code Faster when Doing This Araq
- Why is My Nim Code Faster when Doing This jasonfi
- Why is My Nim Code Faster when Doing Th... Yardanico
- Why is My Nim Code Faster when Doin... awr1
- Why is My Nim Code Faster when ... Isofruit
- Why is My Nim Code Faster when ... demotomohiro
- Why is My Nim Code Faster when ... cblake
- Why is My Nim Code Faster when ... walkr
