Seems my last email got swallowed by the void. Here it is: Nice tests!
You're totally right. I had no idea that Macromedia did any optimization during compilation. Very cool. It's also pretty interesting that Java did not seem to optimize the very same code (the numbers seem to suggest it). haha, thanks for the plug. Scott -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Mark Winterhalder Sent: December 9, 2005 12:09 AM To: Flashcoders mailing list Subject: Re: [Flashcoders] Even odds OK, I ran some tests of my own. After repeating it a couple of times, with various outcomes, the trend seems to be that a) the cast is about 10% faster than the equality, and b) the bitwise and is about 10% faster than the modulo. I used MTASC to compile, FP8 under wine on Linux, and the ActionStep Debug Panel (ActionStep alpha 1 has been released! check it out: actionstep.org). I decided to go with triggering it onKeyDown, to avoid initialization of the player and to be easily able to run repeated tests. Here's the code: var bench:Object = {}; bench.onKeyDown = function () { var repeats:Number = 500000; var i:Number = repeats; var foo; var start:Number = getTimer(); while( i-- ) { foo = ( Math.random() * 100000 )|0; } var overhead:Number = getTimer() - start; trace( "overhead: " + overhead ); i = repeats; start = getTimer(); while( i-- ) { foo = ( Math.random() * 100000 )|0 % 2 == 1; } trace( "modulo, equality: " + ( getTimer() - start - overhead ) ); i = repeats; start = getTimer(); while( i-- ) { foo = Boolean( ( Math.random() * 100000 )|0 % 2 ); } trace( "modulo, cast: " + ( getTimer() - start - overhead ) ); i = repeats; start = getTimer(); while( i-- ) { foo = ( Math.random() * 100000 )|0 & 1 == 1; } trace( "and, equality: " + ( getTimer() - start - overhead ) ); i = repeats; start = getTimer(); while( i-- ) { foo = Boolean( ( Math.random() * 100000 )|0 & 1 ); } trace( "and, cast: " + ( getTimer() - start - overhead ) ); } Key.addListener( bench ); //mark -- http://snafoo.org/ jabber: [EMAIL PROTECTED] _______________________________________________ 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

