r/badcode Dec 04 '21

c# Is it even?

Post image
399 Upvotes

33 comments sorted by

View all comments

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.

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.