Haxe compiled code performance

Pier picture Pier · Aug 14, 2013 · Viewed 8.7k times · Source

How does Haxe compiled code compare in performance to its different targets?

For example, is PHP coming from Haxe faster or slower than original PHP code?

What about Javascript? Flash? C++? Etc.

Is there any serious benchmark out there?

Answer

Jason O'Neil picture Jason O'Neil · Aug 14, 2013

I don't know what benchmarks are out there, and it would certainly differ by target platform, so I guess this is only half an answer. But here are some general points:

  • If you search you can find several benchmarks comparing OpenFL/NME to Flash. One example is this one

  • For CPP, I am told things are slightly slower than regular C++. I imagine hand-optimised C++ could get quite a bit faster. An example benchmark from the creator of HXCPP here

  • For JS, I know Haxe sticks to relative best practices for performance. For example, the strictly typed nature of Haxe tends to result in the best performance with Javascript JIT compilers, so Haxe code is fairly comparable to well-written Javascript. (Note, I'm talking about regular JS here, not canvas / openFL graphics stuff - obviously that would require your own benchmarks).

  • For PHP, I'm not sure how Haxe generated PHP compares to hand written PHP. What I can tell you is that you can almost seamlessly switch from PHP to Neko (both run on apache easily) and you will get code much faster than hand-written PHP. Your bottle necks will come from DB access etc, not the code execution.

  • For flash, search around and you will probably find benchmarks. Haxe gives you some compile time features such as generics, type-safety and function inlining, which can help runtime performance.

Overall

The biggest performance gain with Haxe isn't from comparing it to the hand-written code in the same language, it's from being able to switch to a faster platform without much effort. Write in PHP, switch to neko -> huge speedup. Write in Flash, switch to OpenFL (C++) -> huge speedup.

Hopefully someone else can post some links to more relevant benchmarks :)