ivastly / loop-conditional-benchmark

code for a medium post at medium.com/@ivastly

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

foreach-conditional-benchmark

Rationale

PHP Inspections (EA Extended) plugin for PHPStorm warns noble developer about "avoiding callables in loop conditionals for better performance". Here is the independent benchmark.

Run it

composer require phpbench/phpbench
vendor/bin/phpbench run LoopConditionalBench.php --report=aggregate

Result

count() call in a loop makes the execution ≈ 2.5x slower:

result

About

code for a medium post at medium.com/@ivastly

License:GNU General Public License v3.0


Languages

Language:PHP 100.0%