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

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.