Closed Xuanwo closed 5 years ago
Why is strconv.ParseInt
slow then? I'm curious.
strconv.ParseInt
needs to handle more edge cases like overflow, leading sign and so on. And in order to get all digits, I need to split the string to get them.
May I can do the same thing like
if v < '0' || v > '9' {
if err != nil {
continue
return info, err
}
x = append(x, v)
}
And then convert to int64
.
But Rust does do all those things too.
What I answered is why strconv.ParseInt
slower than v - '0'
trick, I have no idea why Go slower than Rust in swapview.
I've just tested and indeed Go's strconv.ParseInt
takes twice time as Rust's str::parse::<isize>
. I can't tell why because I failed to understand the perf report of the Go program.
strconv.ParseInt
is too slow thatGo
can't beatRust
on my machine now.