Archive for June, 2009
Bit Masking 600% faster than modulus operator 2 comments
Posted at 9:12 am in Flash/Flex
Nuget of wisdom learned today - according to Lee Brimelow using Bit Masking to find odd/even numbers is 600% faster than modulus operator! it’s a pretty common task to need this when working with lists so every other row can have a different style.
Bit Masking
for (var i:uint=0; i<100; i++) { if(i & 1) { row.color = 0xFF0000; // i is odd } else { row.color = 0x000000; // i is even } }
Modulus Operator:
for (var i:uint=0; i<100; i++) { if(i % 2 == 0) { row.color = 0xFF0000; // i is even } else { row.color = 0x000000; // i is odd } }
Thanks Lee ;)