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.
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 whileIncrement whileDecrement doWhileIncrement doWhileDecrement forIn forEachIn forEachInUntyped forEachInPosttyped vecForEach forIncrement |
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
Thanks a lot, it will help me really soon!