We have been working hard to produce something tangible and/or executable to demonstrate some of the usecases, features, and benefits of Peachpie. In honor of Pi Day last week, it seemed like a good idea to produce the first demo of the PHP compiler to .NET by allowing it to compute Pi.

Peachpie Leibniz Demo

First and foremost, we would like to emphasize that Peachpie is still in its absolute infancy and the development is currently in the early stages. However, we felt that in order to get the message across, we invariably needed to show something tangible. Therefore, we taught Peachpie to compute simple algebraic operations, and we demonstrated it via the calculation of Pi.

Test Configuration

Lenovo Thinkpad Yoga 260

Core i7 6500U

8GB DDR4 RAM

Test Source Code

The method used was the Leibniz formula for π. Please refer to this article to see how this formula works. Please be aware that this method is strictly designed for demonstration purposes and is by no means suitable for a precise computation of Pi.

Image 1: Test Source Code

Test Results

The test results indicate that Peachpie outperforms both tested versions of PHP as well as Phalanger by a significant distance. The speed of computation (approximately 11.5 seconds) of Phalanger was comparable to that of PHP 7.0.4 on a x86 processor, while Peachpie calculated the same 100,000,000-step accuracy in just over 2 seconds, as shown by the following table:

Interestingly, both Peachpie and Phalanger were able to calculate a more precise result than the pure PHP versions. Finally, they both run on x32, x64, and any other CPU supported by .NET. It is important to stress that Peachpie is still a work in progress and numerous optimizations can still be made, which will presumably increase the speed even further.

Other Considerations

Aside from the aforementioned performance benefits, there are additional advantages associated with the use of a compiler within Microsoft Visual Studio. Firstly, this popular IDE produces some incredibly useful and user-friendly statistics, as the following examples indicate:

Peachpie:

Image 3: Peachpie Visual Studio Diagnostic Tools

Phalanger:

Image 4: Phalanger Visual Studio Diagnostic Tools

Furthermore, if we compare Phalanger with Peachpie, we can clearly note how Phalanger stresses the garbage collector, while Peachpie’s improved architecture represents an insignificant burden for the GC, keeping the memory consumption at a minimum.

Intermediate Code Comparison

For completion sake, we have also included the comparison of the PHP 5.6 OpCode, the MSIL output produced by Peachpie, as well as the decompiled C# from the Peachpie MSIL, and finally the Phalanger-produced MSIL decompiled into C#: