Replies: 2 comments 4 replies
-
Both package |
Beta Was this translation helpful? Give feedback.
1 reply
-
No reason to pay bounds checking costs. contains_u8 :: proc(str: string, c: u8) -> bool {
for s in str {
if u8(s) == c {
return true
}
}
return false
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I was doing some time sensitive string processing when I noticed a bottleneck on my for loop, specifically
strings.contains_rune()
. I experimented a little to find a way to speed up my code and found a solution (inspired by a solution on another language).I'd like to propose a faster alternative to
strings.contains_rune()
. Instead of checking each characters as rune, we can check them as u8, thus it can be calledcontains_u8()
.Here's the proposed implementation of
contains_u8()
:I tested the performance of
contains_rune()
vscontains_u8()
and the latter is 2.4x faster in my testing. Here's the code I used to test:I can send a pull request as soon as I get the permission.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions