Just a note for myself...
This is a way I used to know if int is even or odd:
Also the best performance gain experienced if above code used inline. Calling a method like this
Upd.: method that you can find in comment below or here - great blog - is even faster. I definetely will use this approach.
This is a way I used to know if int is even or odd:
(i % 2) == 0;And here's a faster way
((i * 0.5) - (i >> 1)) == 0;I was afraid that first part
i * 0.5;can give 1.0000001, for example, due to round error. But it sems that integer numbers divided by 2 without presision lost. If someone have another information, please let me know.
Also the best performance gain experienced if above code used inline. Calling a method like this
private function isEven(i:int):Boolean{
return ((i * 0.5) - (i >> 1)) == 0;
}
is 10 times slower!Upd.: method that you can find in comment below or here - great blog - is even faster. I definetely will use this approach.
Hi there! Have you ever tried something like (0x00000001 & i) == 1? I think it wil be even faster :)
ОтветитьУдалитьWow. Really faster :). Thanks for pointing!
ОтветитьУдалитьYou're welcome!
ОтветитьУдалить