A code monkey randomly typing on a keyboard for an infinite amount of time will almost surely produce brilliance (almost).

Oh Em Gee, All of Those trace() Statements

Posted: November 6th, 2009 | Author: Huyen Tue Dao | Filed under: Development | Tags: , , , , | 2 Comments »

Alright, so I saw this insideria.com article by Tyler Larson about conditionally compiling for cleaner Actionscript when it came out and figured that it would be a good idea for peeling out some performance.  And Procrastee McProcrastinator (that’s me) didn’t get a chance to try any kind of pruning yet.

Then tonight as I’m tidying up some code for my side project I see this tweet by Ben Clinkinbeard noting that adding a trace statement increased a loop’s runtime by 1 second.  So following Larson’s article with a little help from flexexamples.com for setting up a flex-config.xml file, I set conditional compiling for every single trace statement and then compiled a new release build.

Wow.  Just wow.  We’re talking seconds shaved off loading batches of images.  And I’m frequently loading these small batches of images so the additional time was just piling up.

I feel incredibly duh-I-should-have-known-that-I-am-such-a-noob.

But hey, live and learn, right?  And I apologize to folks following me on Twitter for the spam and gratuitous face-palming. :)

Update: Dave Rosenfeld informed me via Twitter that trace actually initiates some disk I/O.  No wonder.


Speed testing/time measuring in .NET, AS3

Posted: March 14th, 2009 | Author: Huyen Tue Dao | Filed under: Development | Tags: , , , , , , | No Comments »

Having had to run some (slightly painful) speed tests as part of a code re-factor for work, I googled a couple of new ways to run speed tests that seem better and are cleaner than the typical method of instantiating Date-type objects at the start and end of the timed code.

.NET: Instead of using DateTime.Now or even instantiating any DateTime objects, just use System.Diagnostics.Stopwatch.  The overhead is much less, since Stopwatch makes use of low-level API.

AS3: The getTimer() function in the flash.utils package returns the number of milliseconds since Flash Player initialized.


answering those nagging questions about efficient syntax…

Posted: December 23rd, 2008 | Author: Huyen Tue Dao | Filed under: Development | Tags: , , , | No Comments »

This flex application runs small timing tests on variations of syntax in AS3.  Curious as to whether there’s a difference between x++, x+=1, and x = x + 1?  How much does the data type of a for loop’s iterator impact runtime?   Yeah, maybe nitpicking about syntax for performance-sake is overkill in many cases, but for anyone working on data-heavy applications with lots of looping/processing of data, a little can go a long way.