Geeks ;)
2005/12/9, Mark Winterhalder <[EMAIL PROTECTED]>: > > 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