PerformanceTest ©2009 Grant Skinner, gskinner.com. Visit www.gskinner.com/libraries/performancetest/ for documentation, updates and more free code. Licensed under the MIT license - see the source file header for more information.
PerformanceTest offers tools to benchmark different aspects of your code and graphics performance (see RenderTest).
It allows very formal approaches to testing, with the creation of typed test objects (subclasses of AbstractTest), and organized
test suites (instances of TestSuite). It also allows very simple, informal testing by passing in a function or a collection
of functions.
At its simplest, you can test a function's execution time using the shortcut ptest method like so:
trace(ptest(myFunction));
This will trace something similar to: [Test time=299.5 min=297 max=302 deviation=0.017]
Tests can be run immediately, or queued. Queuing prevents player time-outs for intense tests and also allows
for cool-down time in between tests.
Tests can be run for multiple iterations, and the tests will return a min, max, and average run time. They also provide a
deviation value that provides a rough indicator of how much the iterations' times varied as a fraction of the average time.
PerformanceTest will automatically force the GC to run before each test iteration to reduce its impact on the results.
currentTest:AbstractTest
[read-only]
Returns the test that is currently running. This is mostly provided for use in conjunction
with the COMPLETE event.
Implementation
public function get currentTest():AbstractTest
currentTestSuite:TestSuite
[read-only]
Returns the test suite that is currently running, or null if none (if the current test does
not belong to a suite, for example). This is mostly provided for use in conjunction with the
COMPLETE event.
Implementation
public function get currentTestSuite():TestSuite
delay:uint
[read-write]
Sets the delay between test iterations. When running a series of high intensity tests,
you may want to increase this value to provide additional cool-down time
between tests.
Implementation
public function get delay():uint
public function set delay(value:uint):void
paused:Boolean
[read-write]
Pauses or resumes the queue.
Implementation
public function get paused():Boolean
public function set paused(value:Boolean):void
public function PerformanceTest()
public static function getInstance():PerformanceTest
Returns a global instance of PerformanceTest. You can also create instances with new PerformanceTest()
, but this
makes it easier to maintain a single global queue of tests.
Returns
public static function queue(o:Object, name:String = null, iterations:uint = 0, loops:uint = 0, params:Array = null):Object
Shortcut method to add a new test or test suite to the global queue. The o param will accept an
AbstractTest or TestSuite instance, a DisplayObject, a function / method, or an object. A DisplayObject
will be converted to a RenderTest. A function will be converted to
an instance of MethodTest, whereas an object will be converted to an instance of TestSuite using
TestSuite.fromObject()
. Returns the AbstractTest or Testsuite that was added.
The other parameters define properties of the test (see Test or TestSuite for details).
If o is an AbstractTest or TestSuite instance, these parameters will override the existing properties if specified.
The params
parameter only applies to function and MethodTest targets.
Parameters
| o:Object |
|
| name:String (default = null )
|
|
| iterations:uint (default = 0 )
|
|
| loops:uint (default = 0 )
|
|
| params:Array (default = null )
|
Returns
public function queueSimpleTest(f:Function, params:Array = null, name:String = null, iterations:uint = 0, loops:uint = 1):MethodTest
Provides a shortcut for creating a new Test instance and adding it to the queue.
Returns the Test instance that was created, which
is useful for adding listeners to it, and accessing the results when it
is complete.
See Test
for information on the parameters.
Parameters
| f:Function |
|
| params:Array (default = null )
|
|
| name:String (default = null )
|
|
| iterations:uint (default = 0 )
|
|
| loops:uint (default = 1 )
|
Returns
public function queueSimpleTestSuite(o:Object, name:String = null, iterations:uint = 1):TestSuite
Provides a shortcut for creating a TestSuite from the o parameter via TestSuite.fromObject()
and adding it to the queue. Returns the TestSuite that was created, which
is useful for adding listeners to it, and accessing the results when it
is complete.
See TestSuite.fromObject()
for information on the parameters.
Parameters
| o:Object |
|
| name:String (default = null )
|
|
| iterations:uint (default = 1 )
|
Returns
public function queueTest(test:AbstractTest):AbstractTest
Adds a test to the queue for this PerformanceTest instance.
The test can be any subclass of AbstractTest (ex. Test, RenderTest).
Returns the AbstractTest instance that was passed in.
Parameters
Returns
public function queueTestSuite(testSuite:TestSuite):TestSuite
Adds a TestSuite to the queue for this PerformanceTest instance.
Returns the TestSuite that was passed in.
Parameters
Returns
public static function run(o:Object, name:String = null, iterations:uint = 0, loops:uint = 0, params:Array = null):Object
Shortcut method that immediately runs a new test or test suite on the global PerformanceTest instance. See
queue
for more details.
Parameters
| o:Object |
|
| name:String (default = null )
|
|
| iterations:uint (default = 0 )
|
|
| loops:uint (default = 0 )
|
|
| params:Array (default = null )
|
Returns
public static function runGC():void
Forces the garbage collector to run. This is used internally to reduce the impact of GC operations on tests,
and to measure memory usage.
public function runSimpleTest(f:Function, params:Array = null, name:String = null, iterations:uint = 0, loops:uint = 1):MethodTest
Provides a shortcut for creating a new Test instance
and running it immediately. Returns the Test instance that was created, which is
handy for accessing the results, such as:
trace(runSimpleTest(myFunction).time);
See Test
for information on the parameters.
Parameters
| f:Function |
|
| params:Array (default = null )
|
|
| name:String (default = null )
|
|
| iterations:uint (default = 0 )
|
|
| loops:uint (default = 1 )
|
Returns
public function runSimpleTestSuite(o:Object, name:String = null, iterations:uint = 1):TestSuite
Provides a shortcut for creating a TestSuite from the o parameter via TestSuite.fromObject()
and running it immediately. Returns the TestSuite that was created, which is
handy for accessing the results, such as:
trace(runSimpleTestSuite(testObj).time);
See TestSuite.fromObject()
for information on the parameters.
Parameters
| o:Object |
|
| name:String (default = null )
|
|
| iterations:uint (default = 1 )
|
Returns
public function runTest(test:AbstractTest):AbstractTest
Immediately runs the specified test.
Returns the AbstractTest instance that was passed in. This is
handy for immediately accessing the results of the test, like so:
trace(runTest(myTest));
Parameters
Returns
public function runTestSuite(testSuite:TestSuite):TestSuite
Immediately runs the specified TestSuite.
Returns the TestSuite that was passed in. This is handy for immediately
accessing the results of the test, like so:
trace(runTestSuite(myTestSuite));
Parameters
Returns
Event object type: flash.events.Event
Dispatched when the last test in the queue completes, and the queue is empty.
Event object type: flash.events.Event
Dispatched when a test completes. You can use currentTest and currentTestSuite to gain access to
the Test that just completed and the suite it belonged to.