PHP internals benchmarks.
MIT License
My personal php internals benchmarks. 🚀 You do not believe? check on your own:
To run:
composer install
vendor/bin/phpbench run benchmarks/__BenchmarkName__ --report=time --retry-threshold=1
How to fast check if array is empty. Remember that empty
can lead to confusion results (automatic cast type).
vendor/bin/phpbench run benchmarks/Array/EmptyArrayBench.php --report=time --retry-threshold=1
+------------------+---------+---------+--------+-------+
| subject | mode | mean | rstdev | diff |
+------------------+---------+---------+--------+-------+
| benchEmpty | 0.027s | 0.027s | 0.41% | 1.00x |
| benchCount | 0.048s | 0.048s | 0.54% | 1.75x |
| benchCountStrict | 0.051s | 0.051s | 0.26% | 1.87x |
| benchComparision | 0.028s | 0.028s | 0.37% | 1.01x |
+------------------+---------+---------+--------+-------+
json_decode
vs unserialize
Faster way to decompress serialized arrays
vendor/bin/phpbench run benchmarks/Array/JsonDecodeBench.php --report=time --retry-threshold=1
suite: 1343ab2c7ea88c1f4e096d667ee3e7fc90c7fbc5, date: 2020-01-14, stime: 10:03:37
+------------------+---------+---------+--------+-------+
| subject | mode | mean | rstdev | diff |
+------------------+---------+---------+--------+-------+
| benchJsonDecode | 7.687s | 7.697s | 0.42% | 3.58x |
| benchUnserialize | 2.155s | 2.150s | 0.33% | 1.00x |
+------------------+---------+---------+--------+-------+
isset
vs in_array
Find value in array (1000 elements).
vendor/bin/phpbench run benchmarks/Array/IsSetVsInArray.php --report=time --retry-threshold=1
+--------------+---------+---------+--------+--------+
| subject | mode | mean | rstdev | diff |
+--------------+---------+---------+--------+--------+
| benchIsSet | 0.095s | 0.095s | 0.45% | 1.00x |
| benchInArray | 3.289s | 3.294s | 0.32% | 34.51x |
+--------------+---------+---------+--------+--------+
pow
function vs **
operator.
vendor/bin/phpbench run benchmarks/Math/PowBench.php --report=time --retry-threshold=1
+-----------------------------+---------+---------+--------+-------+
| subject | mode | mean | rstdev | diff |
+-----------------------------+---------+---------+--------+-------+
| benchPowFunction | 0.090s | 0.090s | 0.40% | 3.60x |
| benchExponentiationOperator | 0.025s | 0.025s | 0.42% | 1.00x |
+-----------------------------+---------+---------+--------+-------+
sqrt
function vs ** .5
operator
vendor/bin/phpbench run benchmarks/Math/SqrtBench.php --report=time --retry-threshold=1
+-----------------------------+---------+---------+--------+-------+
| subject | mode | mean | rstdev | diff |
+-----------------------------+---------+---------+--------+-------+
| benchSqrtFunction | 0.038s | 0.038s | 0.56% | 1.53x |
| benchExponentiationOperator | 0.025s | 0.025s | 0.53% | 1.00x |
+-----------------------------+---------+---------+--------+-------+
in_array
strict modeTest strict mode in in_array
function:
vendor/bin/phpbench run benchmarks/Strict/InArrayBench.php --report=time --retry-threshold=1
+-------------------------+---------+---------+--------+-------+
| subject | mode | mean | rstdev | diff |
+-------------------------+---------+---------+--------+-------+
| benchInArray | 0.053s | 0.053s | 0.41% | 1.00x |
| benchInArrayMixed | 0.094s | 0.094s | 0.51% | 1.78x |
| benchInArrayStrict | 0.066s | 0.066s | 0.48% | 1.26x |
| benchInArrayStrictMixed | 0.078s | 0.078s | 0.41% | 1.48x |
+-------------------------+---------+---------+--------+-------+
match
vs array mapTest if match is faster than using array key to match value:
vendor/bin/phpbench run benchmarks/Syntax/MatchVsArrayMapBench.php --report=time --retry-threshold=1
+---------------+---------+---------+--------+-------+
| subject | mode | mean | rstdev | diff |
+---------------+---------+---------+--------+-------+
| benchMatch | 0.841s | 0.838s | 0.63% | 1.01x |
| benchArrayMap | 0.829s | 0.828s | 0.35% | 1.00x |
+---------------+---------+---------+--------+-------+