The .NET Effect – Microbenchmarking of Include

We previously talked about the include/require functionality, which we recently managed to implement in Peachpie. Now we decided to put the compiler to the test and benchmark the include function against standard PHP and Phalanger.

The ‘Include’ Function

Script inclusion and ‘require’ are some of the most frequently used PHP constructs. Include, in particular, is utilized heavily, and yet represents quite a significant overhead in the PHP language due to the necessity of looking into hashtables. Our benchmarking of this functionality with Peachpie will clearly show another benefit of compiled code.

Peachpie is mostly able to resolve this statically, which allows the compiler to generate the most efficient code within the .NET framework. Here is an example of PHP code, MSIL resulting from compilation with Peachpie, as well as decompiled C#:

The inclusion itself is compiled as following set of MSIL instructions:

// test.php // include "./test2.php";
callvirt instance valuetype [pchpcor]Pchp.Core.PhpValue
call float64 ‘<test2.php>’::
‘<Main>'(Pchp.Core.Context, Pchp.Core.PhpArray, object)

And this is how the whole inclusion line would look like in C#, with all the operators simulating PHP semantic:

// test.php // $x += include "./test2.php";
<locals>.SetItemValue(new IntStringKey("x"),
<locals>.GetItemValue(new IntStringKey("x")),
<test2.php>.<Main>(<ctx>, <locals>, @this) // calling the include directly



We compared the execution of the above code with standard PHP (5.6 and 7), Peachpie and Phalanger. The test configuration remains the same as with preivous microbenchmarks:

Test Configuration

  • Windows 10 x64
  • Lenovo Thinkpad Yoga 260
  • Core i7 6500U
  • 8GB DDR4 RAM

Indeed, Peachpie is on that graph. With an execution time of 0.242 seconds, Peachpie was by far the fastest, followed by Phalanger with 1.001 seconds. The standard versions of PHP both took over a minute to execute the code, with PHP 7 needing 60.884 and PHP 5.6 requiring 69.216 seconds.

Conclusion and Future Work

Because Peachpie can resolve the PHP include nearly statically, there is virtually no overhead associated. Again, we do not expect all microbenchmarks to yield these types of results, and we are aware that this is simply one isolated situation. However, we are looking forward to see the overall performance of a real application once Peachpie will be able to run it in its entirety.

There may be quite a few popular applications that could benefit from running on .NET…

Posted on May 23, 2016, in category Benchmark, tags: , , , , , , , , , ,