Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there any performance gain in using latest PHP syntax? [closed]

Tags:

syntax

php

With the latest release of PHP 5.4.x soon to be 5.5, there has been quite a few new syntax introduce. I understand their significance in terms of code readability, less(er) typing by programmer, bug fixes etc.

But I am particularly keen on knowing how significant (if any) improvement in performance in terms of using these new syntax. Does the PHP interpreter and/or the Zend engine perform faster/better if more of the new syntax are used??

Or may be I am missing the whole point. Need your expertise knowledge and thoughts on this. Thank you!

like image 610
shawndreck Avatar asked Feb 17 '23 23:02

shawndreck


1 Answers

New syntax is added to a language to make writing the program easier and make the code easier to organise; not generally to make it perform any better. You shouldn't be thinking of using a specific syntax for performance reasons, but because it makes your code better, easier to work with, easier to read, etc.

For instance, PHP 5.5 introduces "Generator" syntax (the yield keyword). This is an improved way of writing Iterators. But it won't provide any performance difference between writing the Iterator-style code; it'll basically be doing the same thing under the hood. The important point is that it is much easier to write a simple Generator than writing the same code using an Iterator. The code is shorter, neater and easier to understand. It won't run any faster, but it will be much easier to work with. That's the whole point.

However, PHP does have a good track record of significantly improving performance in the language with every release. You don't even need to use the new features -- just upgrade to the latest version, and you'll get a performance boost from your existing code. In some cases, performance can improve by 50% or more. Given that, the upgrade should be a no-brainer; being able to use the new language features is an added bonus on top of the performance gains.

There are plenty of benchmarks out there to prove it; here's one example that covers PHP v5.1 through to 5.4.

(I haven't seen a good benchmark for v5.5 yet, presumably because it's still being worked on, but you can be sure benchmarks will be published soon after it's released)

like image 80
SDC Avatar answered Apr 26 '23 12:04

SDC