A Performance test class for AS3 Mobile dev

I currently need to do some bench to optimize my iPhone game. (TapDoctor ;))
So I’m working on a simple class to facilitate the work, inspired by the Grant Skinner performance test, but with the mobile constraint : be as light as possible.

Bench class on github

Use :

Bench.output = output;
 
Bench.push(test1, "This is the 1st test with 5 iterations", 5);
Bench.push(test2, "This is the 2nd test with 5 iterations", 5);
 
Bench.run();
 
private function test1():void {
	// here what I want to bench
}
 
private function test2():void {
	// here what I want to bench
}
 
private function output(result : String) : void {
	//see https://github.com/jonasmonnier/Mobilo/blob/master/src/com/mobilo/bench/BenchView.as
}

I took the loops from grant skinner to make my first test.

Loop test class on Github

private function forIncrement() : void {
	for (var i : uint = 0; i < loops; i++) {
		var a : uint = i;
	}
}
 
private function forDecrement() : void {
	for (var i : uint = loops; i > 0; i--) {
		var a : uint = i - 1;
	}
}
 
private function whileIncrement() : void {
	var i : uint = 0;
	while (i < loops) {
		var a : uint = i;
		i++;
	}
}
 
private function whileDecrement() : void {
	var i : uint = loops;
	while (--i) {
		var a : uint = i;
	}
}
 
private function doWhileIncrement() : void {
	var i : uint = 0;
	do {
		var a : uint = i;
	} while (++i < loops);
}
 
private function doWhileDecrement() : void {
	var i : uint = loops - 1;
	do {
		var a : uint = i;
	} while (i--);
}
 
private function forIn() : void {
	for (var b:* in vec) {
		var a : uint = b;
	}
}
 
private function forEachIn() : void {
	for each (var b:Boolean in vec) {
		var a : uint = loops;
	}
}
 
private function forEachInUntyped() : void {
	for each (var b:* in vec) {
		var a : uint = loops;
	}
}
 
private function forEachInPosttyped() : void {
	for each (var b:* in vec) {
		var c : Boolean = b as Boolean;
		var a : uint = loops;
	}
}
 
private function vecForEach() : void {
	vec.forEach(vecForEachF);
}
 
// helper functions:
private function vecForEachF(item : Boolean, index : int, vec : Vector.<Boolean>) : void {
	var a : uint = index;
}

I test 1 million loops 5 times with a 1 second delay between each test.
Some results are a bit surprising…

Your flash player (wait 60s) > scrollable AIR IOS 2.7 on my 3GS
forIncrement
————————————————————
time=0 ms [memory total=5.701 private=7.874 free=0.250]
time=0 ms [memory total=5.596 private=7.874 free=0.356]
time=0 ms [memory total=5.576 private=7.874 free=0.375]
time=0 ms [memory total=5.572 private=7.854 free=0.379]
time=0 ms [memory total=5.572 private=7.854 free=0.379]
————————————————————
time=0 max=0 min=0 deviation=NaN 

forDecrement
————————————————————
time=0 ms [memory total=5.576 private=7.854 free=0.375]
time=0 ms [memory total=5.572 private=7.854 free=0.379]
time=0 ms [memory total=5.572 private=7.854 free=0.379]
time=0 ms [memory total=5.572 private=7.854 free=0.379]
time=0 ms [memory total=5.572 private=7.854 free=0.379]
————————————————————
time=0 max=0 min=0 deviation=NaN

whileIncrement
————————————————————
time=0 ms [memory total=5.576 private=7.854 free=0.375]
time=0 ms [memory total=5.572 private=7.854 free=0.379]
time=0 ms [memory total=5.568 private=7.854 free=0.383]
time=0 ms [memory total=5.568 private=7.854 free=0.383]
time=0 ms [memory total=5.568 private=7.854 free=0.383]
————————————————————
time=0 max=0 min=0 deviation=NaN

whileDecrement
————————————————————
time=302 ms [memory total=5.568 private=7.854 free=0.383]
time=290 ms [memory total=5.564 private=7.854 free=0.387]
time=290 ms [memory total=5.564 private=7.854 free=0.387]
time=295 ms [memory total=5.564 private=7.854 free=0.387]
time=291 ms [memory total=5.564 private=7.854 free=0.387]
————————————————————
time=294 max=302 min=290 deviation=0.041

doWhileIncrement
————————————————————
time=83 ms [memory total=5.568 private=7.854 free=0.383]
time=83 ms [memory total=5.564 private=7.854 free=0.387]
time=83 ms [memory total=5.560 private=7.854 free=0.391]
time=83 ms [memory total=5.553 private=7.858 free=0.399]
time=83 ms [memory total=5.553 private=7.858 free=0.399]
————————————————————
time=83 max=83 min=83 deviation=0.000

doWhileDecrement
————————————————————
time=267 ms [memory total=5.557 private=7.858 free=0.395]
time=267 ms [memory total=5.553 private=7.858 free=0.399]
time=266 ms [memory total=5.553 private=7.858 free=0.399]
time=266 ms [memory total=5.553 private=7.858 free=0.399]
time=267 ms [memory total=5.553 private=7.858 free=0.399]
————————————————————
time=267 max=267 min=266 deviation=0.004

forIn
————————————————————
time=398 ms [memory total=5.557 private=7.858 free=0.395]
time=396 ms [memory total=5.553 private=7.858 free=0.399]
time=407 ms [memory total=5.553 private=7.858 free=0.399]
time=396 ms [memory total=5.553 private=7.858 free=0.399]
time=396 ms [memory total=5.553 private=7.862 free=0.399]
————————————————————
time=399 max=407 min=396 deviation=0.028

forEachIn
————————————————————
time=398 ms [memory total=5.557 private=7.862 free=0.395]
time=398 ms [memory total=5.549 private=7.862 free=0.402]
time=398 ms [memory total=5.549 private=7.862 free=0.402]
time=398 ms [memory total=5.549 private=7.862 free=0.402]
time=398 ms [memory total=5.553 private=7.862 free=0.399]
————————————————————
time=398 max=398 min=398 deviation=0.000

forEachInUntyped
————————————————————
time=398 ms [memory total=5.557 private=7.862 free=0.395]
time=397 ms [memory total=5.553 private=7.862 free=0.399]
time=398 ms [memory total=5.553 private=7.862 free=0.399]
time=436 ms [memory total=5.553 private=7.862 free=0.399]
time=406 ms [memory total=5.553 private=7.866 free=0.399]
————————————————————
time=407 max=436 min=397 deviation=0.096

forEachInPosttyped
————————————————————
time=436 ms [memory total=5.564 private=7.866 free=0.387]
time=437 ms [memory total=5.560 private=7.866 free=0.391]
time=446 ms [memory total=5.557 private=7.866 free=0.395]
time=443 ms [memory total=5.557 private=7.874 free=0.395]
time=436 ms [memory total=5.557 private=7.874 free=0.395]
————————————————————
time=440 max=446 min=436 deviation=0.023

vecForEach
————————————————————
time=2400 ms [memory total=5.623 private=7.878 free=0.328]
time=2410 ms [memory total=5.619 private=7.870 free=0.332]
time=2411 ms [memory total=5.619 private=7.870 free=0.332]
time=2392 ms [memory total=5.619 private=7.870 free=0.332]
time=2406 ms [memory total=5.619 private=7.870 free=0.332]
————————————————————
time=2404 max=2411 min=2392 deviation=0.008

forIncrement
————————————————————
time=0 ms [memory total=5.623 private=7.870 free=0.328]
time=0 ms [memory total=5.619 private=7.870 free=0.332]
time=0 ms [memory total=5.619 private=7.870 free=0.332]
time=0 ms [memory total=5.619 private=7.870 free=0.332]
time=0 ms [memory total=5.619 private=7.870 free=0.332]
————————————————————
time=0 max=0 min=0 deviation=NaN

Note that Garbage Collection is not forced โ€‹โ€‹with Flash Player in this version.

More info in an upcoming post…

Nobody to point out my spelling mistakes ?
Hope it is understandable ๐Ÿ™‚

One thought on “A Performance test class for AS3 Mobile dev

Leave a Reply

Your email address will not be published. Required fields are marked *