Some people often ask me what are the advantages of Haxe in terms of speed.
Of course, there are many runtime optimizations in Haxe that make your program run faster, but one of the very important thing to me is also the speed of the compiler. Compiling quickly help you to test some minor changes more often, to find and fix errors faster, and prevent you from losing your concentration and your time waiting for the compiler to be done with its work.
So what about comparing Haxe and AS3 compilers speed ?
First, Haxe starts with an obvious disadvantage : because it has type inference, structural subtyping and generics, the compiler needs to perform much more type checks that in more classical type system such as AS3 one.
But let's see how it rates anyway.
I tried the following : compiling the whole hx-format library, which is 64 files / 10.000 lines / 300KB of Haxe to Flash9. Here's the commandline for that :
time haxe -swf9 format.swf -cp hxformat/tests/all All.hx
On my QuadCore (Haxe compiler does not yet use multicores, that's something we need to fix btw) the command run in
0.31 seconds which is a decent enough.
Now, I'm generating the corresponding AS3 output by using :
haxe -as3 format_as3 -cp hxformat/tests/all All.hx
(a small fix was needed in
format.amf.Reader since some expression is not accepted by AS3 generator, but well...)
Then here we go with the AS3 compilation. This was actually a bit hard, because I found that the
format.swf.Namespace class is actually a reserved name, so had to do a bit of renaming here and there, then the
mxmlc compiler crashed when compiling
format.mp3.MPEG (but maybe I'm not up-to-date), and I had to recreate a
All.as file that would ensure that all files will get compiled (since
import in AS3 is lazy while it's not in Haxe), and so some other minor fixes. Took me 15 minutes but I was able to compile everything except
So at last here we go :
mxmlc --output all.swf -compiler.optimize All.as
Took... 3.3 seconds on my QuadCore
So, even if we take out something like 1 second for JVM startup (
mxmlc is Java) then we still have Haxe which is... 7x faster than
Now, that's just a benchmark, I would be happy if other people could try the same with their own project to see if I'm accurate enough or not, but this seems to confirm that indeed, Haxe is fast !
(anybody who remember no more coffee break while compiling ?)