PerformanceTest-Klassen von Grant Skinner
8
Feb
2010
Heute möchte ich kurz auf eine neue Veröffentlichung von Grant Skinner hinweisen. Performancetest dient für Performancetests in ActionScript 3 und liegt nun in überarbeiteten Version als zweite Beta vor.
Einige der Hauptfeatures sind:
- Track time, memory usage and retained (unreleased) memory for functions.
- Test rendering time for any display object.
- Write simple one line tests, or build formal test suites.
- Run multiple iterations of tests to get min, max, and deviation values.
- Run tests synchronously, or queue them to run them asynchronously.
Beispiel
Das folgende Beispiel belegt, dass x = x + 3 schneller ist, als dreimal die 1 in drei Codezeile nacheinander zu addieren. Das Ergebnis wird so präsentiert:
[TestSuite name='Calculator' tareTime=0 time=-1]
[MethodTest name='variante1' time=21.0 min=20 max=24 ...
[MethodTest name='variante2' time=33.3 min=33 max=34 ...
Variante 1 dauert 21ms, während der Dreizeiler 33ms benötigt.
Der Quellcode ist in zwei Klassen aufgeteilt. Einmal die Hauptklasse und einmal die Klasse mit dem Test. Generell gibt es in PerformanceTest-Bibliothek auch noch einfacher Testmöglichkeiten, so dass diese Aufteilung nach zwangsweise notwendig ist.
Actionscript:
-
package {
-
import tests.*;
-
-
import com.gskinner.performance.*;
-
-
import flash.display.Sprite;
-
import flash.text.TextField;
-
-
public class PerformanceTestDemo extends Sprite {
-
-
public var textField:TextField = new TextField();
-
-
public function PerformanceTestDemo() {
-
// text field
-
new TextLog().out = out;
-
addChild(textField);
-
textField.width = 500;
-
-
// test
-
PerformanceTest.queue(new Calculator());
-
-
}
-
-
protected function out(str:*):void {
-
textField.appendText(String(str)+"\n");
-
}
-
-
-
}
-
}
Actionscript:
-
package tests {
-
-
import com.gskinner.performance.TestSuite;
-
import com.gskinner.performance.MethodTest;
-
-
public class Calculator extends TestSuite {
-
-
public var loops:uint = 100000;
-
-
public function Calculator() {
-
name = "Calculator";
-
description = "Vergleiche Addition. "+loops+" loops.";
-
iterations = 4;
-
tests = [
-
new MethodTest(variante1, null, "variante1", 0, 1, "x + 3"),
-
new MethodTest(variante2, null, "variante2", 0, 1, "x + 1; x + 1; x + 1")
-
];
-
}
-
-
-
public function variante1():void {
-
for (var i:uint=0; i<loops; i++) {
-
var x:Number = 0;
-
x = x + 3;
-
}
-
}
-
-
public function variante2():void {
-
for (var i:uint=0; i<loops; i++) {
-
var x:Number = 0;
-
x = x + 1;
-
x = x + 1;
-
x = x + 1;
-
}
-
}
-
-
}
-
-
}
Link: Grant Skinner PerformanceTest
Schreibe einen Kommentar