Frederick Vanbrabant has a new post to his site sharing some performance tips you can integrate into your PHP code to help improve its overall processing time. He also talks some about a few that are just myths and debunks them.
We’ve all been there before, you submit a pull request and moments later you get a comment like: “Hey you should use a native function here, they are so much faster” or “You can declare this final, that way we save some processing power”.
It’s great that we as developers keep an eye on this, but how true are these thing. And are they still a thing in newer PHP versions?
He goes through a list of ten tricks that have been widely shared and creates some simple benchmarks around their use:
- single versus double quotes
- JSON handling versus XML handling
- speed difference from using layered objects
- native array functions versus loops
- fetching an array item by quoted ID versus just ID
- performance difference of throwing exceptions
- impact of unused variables
- magic methods versus normal methods
- final versus non-final classes
- comments in code
For each of the items in the list he includes the example code he used for the benchmark and the output from the PHPBench tool.