Zynga recently released Playscript compiler, which can compile Actionscript 3 code for Mono runtime (GitHub).
I did very basic benchmark test for Vector access, to see the difference in performance between the app produce with “native” compiler and Playscript compiler. Both apps was compiled to run on iOS device.
“Native” compilation:
- AIR 3.6
- ASC2
- ad-hoc build
Playscript compilation:
- App Store release build
Here is Actionscript 3 portion of code:
package { import flash.utils.getTimer; public class Benchmark { public var results:Array; private const SIZE:uint = 2000; private const REPS:uint = 1000; private var _tests:Vector. = new Vector.(); public function Benchmark() { _tests.push(vectorAccess); } public function performTest():void { results = new Array(); log("Total repeats", (SIZE* REPS).toString()); for each(var f:Function in _tests) { f(); } } private function vectorAccess():void { var k:int; var v:Vector. = new Vector.(); for (var i:int = 0; i & lt; SIZE; i++) { v.push(int(Math.random() * 1000)); } var t:Number = getTimer(); for (var ii:int = 0; ii & lt; REPS; ii++) { for (var j:int = 0; j & lt; SIZE; j++) { k = v[j]; } } log("Vector access", (getTimer() - t).toString()); } private function log(s1:String, s2:String):void { var r:Array = new Array(); r.push(s1); r.push(s2); results.push(r); } } }
Results (rounded, tested on iPad 3):
“Native”:
- Total amount of iterations: 2 000 000;
- Vector (of int(s)) access – 50 milliseconds
Playscript:
- Total amount of iterations: 2 000 000;
- Vector (of int(s)) access – 150 milliseconds