On 12/9/05, Scott Hyndman <[EMAIL PROTECTED]> wrote: > I just did a test. The bitwise approach is not faster...although when you > think about it, it really should be.
Hi Scott, the test won't work because (50010001 % 2 == 1) always resolves to false and the compiler will optimize it (at least MMC, not sure about MTASC). basically, the same is true for Boolean(50010001 & 1), but maybe it just optimizes the (50010001 & 1) part because Boolean might be a custom replacement for the intrinsic class? mark > Here is the test code: > > // Modulo - Time ~225ms > var time:Number = getTimer(); > for (var i:Number = 0; i < 80000; i++) { > var isOdd:Boolean = 50010001 % 2 == 1; > } > trace(getTimer() - time); > > // Bitwise And - Time: ~356ms > time = getTimer(); > for (var i:Number = 0; i < 80000; i++) { > var isOdd:Boolean = Boolean(50010001 & 1); > } > trace(getTimer() - time); > > I also did a quick test in Java. The bitwise AND approach is about 50% > faster...really makes you wonder. Maybe AS3 is an improvement. > > Scott > > -----Original Message----- > From: [EMAIL PROTECTED] on behalf of Boon Chew > Sent: Thu 12/8/2005 9:34 PM > To: Flashcoders mailing list > Cc: > Subject: Re: [Flashcoders] Even odds > > Yet another way (and probably the fastest): > > var isOdd:Boolean = Boolean(num & 1); > > - boon > > Mike Boutin <[EMAIL PROTECTED]> wrote: Is it possible to check a number to > see if its even / odd? > > > Thanks! > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > > > > --------------------------------- > Yahoo! Shopping > Find Great Deals on Holiday Gifts at Yahoo! Shopping > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > > > > > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > > -- http://snafoo.org/ jabber: [EMAIL PROTECTED] _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders