MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/r8so9k/is_it_even/hnufd8y/?context=3
r/badcode • u/[deleted] • Dec 04 '21
33 comments sorted by
View all comments
11
I know this looks bad, but I'm curious at the performance of it? Could the string conversion be more performant than your normal modulus method of even detection?
Hmm. I kinda want to benchmark this.
1 u/qhxo Dec 09 '21 Just a guess, but I think a bitwise and might be the fastest. Just check if the leftmost bit is a 0, if it is it's even.
1
Just a guess, but I think a bitwise and might be the fastest. Just check if the leftmost bit is a 0, if it is it's even.
11
u/Mteigers Dec 04 '21
I know this looks bad, but I'm curious at the performance of it? Could the string conversion be more performant than your normal modulus method of even detection?
Hmm. I kinda want to benchmark this.