Home

Awesome

Benchmark of PSR-7 and PSR-17 implementation

This test performance for PSR-7 and PSR-17 implementations. We just create Request, ServerRequest, Reponse, Stream, Uri, UploadFile and corresponding factories objects and measure the time. Note that the number does not really matter. It is the difference between them that are interesting (higher is better).

Note: For more honest test results, disable the PHP CLI debugger and profiler tools before running the benchmark.

Usage

Install:

git clone git@github.com:devanych/psr-http-benchmark.git
cd psr-http-benchmark
composer update

Runs:

php benchmark.php <package> [runs]

# The default number of runs is 30000.
php benchmark.php httpsoft 30000
# equivalently to:
php benchmark.php httpsoft

# guzzlehttp/psr7:
php benchmark.php guzzle

# httpsoft/http-message:
php benchmark.php httpsoft

# laminas/laminas-diactoros:
php benchmark.php laminas

# nyholm/psr7:
php benchmark.php nyholm

# slim/psr7:
php benchmark.php slim

Run and result:

php benchmark.php httpsoft

Runs: 30,000
Runs per second: 19544
Average time per run: 0.0512 ms
Total time: 1.5349 s

Test results

Runs: 30,000GuzzleHttpSoftLaminasNyholmSlim
Runs per second1586819544122571902212117
Average time per run0.0630 ms0.0512 ms0.0816 ms0.0526 ms0.0825 ms
Total time1.8905 s1.5349 s2.4474 s1.5771 s2.4757 s

Runs: 50,000GuzzleHttpSoftLaminasNyholmSlim
Runs per second1569819438125211900312046
Average time per run0.0637 ms0.0514 ms0.0799 ms0.0526 ms0.0830 ms
Total time3.1849 s2.5723 s3.9932 s2.6311 s4.1504 s

Runs: 100,000GuzzleHttpSoftLaminasNyholmSlim
Runs per second1547119436124471912112041
Average time per run0.0647 ms0.0515 ms0.0803 ms0.0523 ms0.0830 ms
Total time6.4685 s5.1450 s8.0338 s5.2298 s8.3044 s