Skip to content

Commit e57a6f5

Browse files
authored
Merge pull request #3 from myaghobi/v1.4
V1.4
2 parents b3d265c + bb4991c commit e57a6f5

File tree

108 files changed

+632
-149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+632
-149
lines changed

README.md

100644100755
Lines changed: 62 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Components like Template engines or ORM/Database libraries are out of scope in t
1818
- [Commands](#commands)
1919
- [Benchmarks](#benchmarks)
2020
- [Latest](#latest)
21-
- [Old](#old)
2221
- [OPCache](#results-with-opcache)
2322
- [References](#references)
2423
- [License](#license)
@@ -29,64 +28,73 @@ Components like Template engines or ORM/Database libraries are out of scope in t
2928

3029
This is `master` branch.
3130

32-
* Install a framework according to the official documentation.
31+
* Install a framework via `composer` according to the official documentation.
3332
* Use the default configuration.
3433
* Don't remove any components/configurations even if they are not used.
3534
* With minimum changes to run this benchmark.
3635
* Set environment production/Turn off debug mode.
3736
* Run the general optimization in your production environment, like `--optimize-autoloader` for the composer.
38-
* Use controller or action class.
37+
* Use controller class.
3938

40-
Some frameworks are optimized, some are not, so some people may think using default configuration is not fair. The dept of optimizing a framework depends on the developer's knowledge & experienced, it's the rabbit hole and there is no point in that for benchmarking. I think the default configuration of frameworks is a good starting point to have the ranking points.
39+
Some frameworks are optimized, some are not, so some people may think using default configuration is not fair. The dept of optimizing a framework depends on the developer's experienced too, so it's the rabbit hole and there is no point in that for benchmarking. I think the default configuration of frameworks is a good starting point to have the ranking points.
4140

42-
If you find something wrong with my code, please feel free to send Pull Requests. But please note optimizing for the "Hello World" is not acceptable! Building the fastest "Hello World" application is not the goal of this project.
41+
If you find something wrong with my code, feel free to send PR. But please note optimizing for the "Hello World" is not acceptable! Building the fastest "Hello World" application is not the goal of this project.
4342

4443

4544
## How to Benchmark
4645

4746
If you want to benchmark PHP extension frameworks like Phalcon, you need to install the extenstions.
4847

49-
1- Install source code as <http://localhost/php-frameworks-bench/>:
48+
1- Download & install the library in your localhost:
5049

5150
```
52-
# you can use --branch vx.x
51+
# instead you can use --branch vx.x
5352
$ git clone https://github.com/myaghobi/php-frameworks-bench.git
5453
$ cd php-frameworks-bench
54+
# run the setup & follow the progress
5555
$ bash setup.sh
5656
```
5757

58-
2- Run benchmarks:
58+
2- To make sure everything is ok:
59+
60+
```
61+
# this is optional
62+
$ bash check.sh
63+
```
64+
65+
3- Run benchmarks:
5966

6067
```
6168
$ bash benchmark.sh
6269
```
6370

64-
3- Check the resuts:
71+
4- Check the resuts:
6572

6673
<http://localhost/php-frameworks-bench/>
6774

75+
6876
## Commands
6977

7078
```
71-
# install | create-project frameworks
72-
$ bash setup.sh
73-
74-
# run the benchmark
75-
$ bash benchmark.sh
76-
77-
# composer update
79+
# composer update for each framework
7880
$ bash update.sh
7981
8082
# to clean them all
81-
# then you can use setup.sh
82-
# trobble? use it with `sudo`
83+
# trouble? run it then
84+
# you can use setup.sh
8385
$ bash clean.sh
86+
87+
# clear the cache of frameworks
88+
$ bash clear-cache.sh
89+
90+
# show the table of last benchmark
91+
$ bash show-table.sh
8492
```
8593

8694
To specify the frameworks, put them after each command:
8795

8896
```
89-
$ bash benchmark.sh laravel-9.1.3/ slim-4.10/ fatfree-3.7.3/
97+
$ bash benchmark.sh laravel-9.1/ slim-4.10/ fatfree-3.8.0/
9098
...
9199
```
92100

@@ -97,13 +105,15 @@ $ bash benchmark.sh laravel-9.1.3/ slim-4.10/ fatfree-3.7.3/
97105

98106
#### Environment
99107

100-
* Ubuntu 20.04 LTS 64bit
101-
* PHP 8.1.4 (LAMP)
102-
* CPU Core i7 [email protected]
108+
* Ubuntu 22.04 LTS 64bit
109+
* PHP 8.1.5
110+
* OPCache disabled
111+
* Apache 2.4.52
112+
* CPU Core i7 2600K@4Ghz
103113
* Memory 16G
104114

105115

106-
#### Results (2022/5/9)
116+
#### Results (2022/5/15)
107117

108118
These are my benchmarks, not yours. **I encourage you to run on your (production equivalent) environments.**
109119

@@ -112,59 +122,32 @@ These are my benchmarks, not yours. **I encourage you to run on your (production
112122
![Benchmark Results Graph Execution Time](screenshots/php-frameworks-bench-exectime.png)
113123
![Benchmark Results Graph Included Files](screenshots/php-frameworks-bench-includedfiles.png)
114124

115-
PHP 8.1.4 (LAMP)
116-
|framework |requests per second|relative|peak memory|relative|
117-
|-------------------|------------------:|-------:|----------:|-------:|
118-
|pure-php | 25,363.33|25,363.3| 0.34| 0.3|
119-
|phroute-2.1 | 20,871.63|20,871.6| 0.34| 0.3|
120-
|fastroute-1.3 | 20,692.36|20,692.4| 0.34| 0.3|
121-
|siler-1.7.9 | 15,140.00|15,140.0| 0.36| 0.4|
122-
|fatfree-3.8.0 | 13,172.39|13,172.4| 0.39| 0.4|
123-
|slim-4.10 | 10,863.08|10,863.1| 0.38| 0.4|
124-
|slim-3.12 | 10,630.10|10,630.1| 0.39| 0.4|
125-
|yii-2.0-basic | 8,382.51| 8,382.5| 0.69| 0.7|
126-
|silex-2.3 | 8,017.40| 8,017.4| 0.39| 0.4|
127-
|symfony-5.4 | 7,309.46| 7,309.5| 0.46| 0.5|
128-
|symfony-6.0 | 7,272.85| 7,272.9| 0.45| 0.5|
129-
|lumen-9.0.0 | 4,990.60| 4,990.6| 0.39| 0.4|
130-
|cakephp-4.3 | 4,471.16| 4,471.2| 0.43| 0.4|
131-
|fuelphp-1.9 | 3,728.35| 3,728.4| 0.45| 0.5|
132-
|codeigniter-4.1.9 | 1,671.15| 1,671.2| 1.46| 1.5|
133-
|laravel-9.1.3 | 826.64| 826.6| 0.77| 0.8|
134-
135-
136-
### Old
137-
138-
#### Environment
139-
140-
* Windows 10 64bit (bash executed on WSL 2)
141-
* PHP 8.0 (XAMPP x64)
142-
* CPU Core i7 [email protected]
143-
* Memory 16G
144-
145-
146-
#### Results (2021/12/01)
147-
148125
|framework |requests per second|relative|peak memory|relative|
149126
|-------------------|------------------:|-------:|----------:|-------:|
150-
|pure-php | 2,476.19| 2,476.2| 0.42| 0.4|
151-
|fastroute-1.3 | 1,208.93| 1,208.9| 0.57| 0.6|
152-
|phroute-2.1 | 1,201.83| 1,201.8| 0.58| 0.6|
153-
|fatfree-3.7.3 | 695.23| 695.2| 1.67| 1.7|
154-
|siler-1.7.9 | 520.31| 520.3| 1.19| 1.2|
155-
|yii-2.0.14-basic | 269.47| 269.5| 2.76| 2.8|
156-
|slim-4.9 | 239.09| 239.1| 1.60| 1.6|
157-
|silex-2.3 | 224.29| 224.3| 2.28| 2.3|
158-
|slim-4.3 | 223.43| 223.4| 1.55| 1.6|
159-
|fuelphp-1.8 | 180.84| 180.8| 2.72| 2.7|
160-
|lumen-8.1.2 | 162.19| 162.2| 3.45| 3.5|
161-
|cakephp-4.3 | 108.52| 108.5| 4.49| 4.5|
162-
|symfony-5.3 | 96.57| 96.6| 5.49| 5.5|
163-
|codeigniter-4.1.5 | 75.94| 75.9| 3.37| 3.4|
164-
|laravel-8.6.6 | 39.96| 40.0| 11.90| 11.9|
165-
166-
167-
### Results with OPCache
127+
|pure-php | 22,427.34|22,427.3| 0.42| 0.4|
128+
|fastroute-1.3 | 4,224.76| 4,224.8| 0.56| 0.6|
129+
|phroute-2.2 | 3,901.59| 3,901.6| 0.58| 0.6|
130+
|leaf-3.0 | 1,539.38| 1,539.4| 1.05| 1.1|
131+
|fatfree-3.8.0 | 1,414.71| 1,414.7| 1.67| 1.7|
132+
|siler-1.7.9 | 1,314.15| 1,314.2| 1.17| 1.2|
133+
|frameworkx-dev | 972.97| 973.0| 1.41| 1.4|
134+
|slim-3.12 | 969.54| 969.5| 1.40| 1.4|
135+
|slim-4.10 | 752.96| 753.0| 1.60| 1.6|
136+
|yii-2.0-basic | 510.90| 510.9| 2.72| 2.7|
137+
|silex-2.3 | 510.51| 510.5| 2.18| 2.2|
138+
|fuelphp-1.9 | 410.60| 410.6| 2.50| 2.5|
139+
|ubiquity-2.4.x.dev | 379.51| 379.5| 2.33| 2.3|
140+
|lumen-9.0 | 329.70| 329.7| 3.39| 3.4|
141+
|symfony-6.0 | 293.11| 293.1| 3.85| 3.9|
142+
|symfony-5.4 | 291.41| 291.4| 3.77| 3.8|
143+
|codeigniter-4.1 | 290.94| 290.9| 3.39| 3.4|
144+
|laminas-2.0.x.dev | 284.43| 284.4| 3.52| 3.5|
145+
|cakephp-4.3 | 232.68| 232.7| 4.45| 4.5|
146+
|laravel-9.1 | 93.47| 93.5| 11.04| 11.0|
147+
148+
149+
150+
### Results with OPCache (old version)
168151
[![IMAGE ALT TEXT](http://img.youtube.com/vi/BUcxalvD92U/0.jpg)](http://www.youtube.com/watch?v=BUcxalvD92U "PHP OPCache Benchmarks, a Comparison for Popular Frameworks")
169152

170153

@@ -176,19 +159,23 @@ Note: This project is based on
176159
* [CodeIgniter](https://github.com/codeigniter4/CodeIgniter4)
177160
* [FastRoute](https://github.com/nikic/FastRoute)
178161
* [FatFree](https://github.com/bcosca/fatfree)
162+
* [FrameworkX](https://github.com/clue/framework-x)
179163
* [FuelPHP](https://github.com/fuelphp/fuelphp)
164+
* [Laminas](https://github.com/laminas)
180165
* [Laravel](https://github.com/laravel/laravel)
166+
* [Leaf](https://github.com/leafsphp/leaf)
181167
* [Lumen](https://github.com/laravel/lumen)
182168
* [PhRoute](https://github.com/mrjgreen/phroute)
183169
* [Siler](https://github.com/leocavalcante/siler)
184170
* [Silex](https://github.com/silexphp/Silex)
185171
* [Slim](https://github.com/slimphp/Slim)
186172
* [Symfony](https://github.com/symfony/symfony)
173+
* [Ubiquity](https://github.com/phpMv/ubiquity)
187174
* [Yii](https://github.com/yiisoft/yii2)
188175

189176

190177
## License
191178

192-
You are allowed to use this plugin under the terms of the GNU General Public License version 2.
179+
You are allowed to use this plugin/project under the terms of the GNU General Public License version 2.
193180

194181
Copyright (C) 2022 Mohammad Yaghobi

benchmarks/_functions.sh

100644100755
Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,48 @@ benchmark () {
44
output_wrk="output/$fw.wrk.log"
55
output="output/$fw.output"
66

7-
# get rps
8-
# for this version of wrk -R (--rate) is necessary to use for wsl
7+
url_output=$(curl -s "$url")
8+
reqsubstr="Hello World!"
9+
10+
# to make sure the appropriate response is reachable
11+
# otherwise, there is no point running the benchmark
12+
if ! [ -z "${url_output##*$reqsubstr*}" ] ;then
13+
tmp=`cat "$output"`
14+
error="$error$tmp"
15+
echo "error!"
16+
echo -e "$fw\n$error" >> "$error_file"
17+
echo "---" >> "$error_file"
18+
19+
echo "$fw: 0: 0: 0: 0" >> "$results_file"
20+
return 1
21+
fi
22+
23+
config_wrk="wrk -t50 -c1000 -d10s"
24+
25+
# is it wsl!?
26+
# if you're using wsl, it's necessary to put -R (--rate)
27+
# in this version of wrk
928
# I used a large number to make sure there be no limitation of rate
1029
# for a high end server, you can increase first two parameters
11-
# is it wsl!?
1230
if grep -q Microsoft /proc/version; then
13-
echo "wrk -t50 -c1000 -d10s -R1000g $url"
14-
wrk -t50 -c1000 -d10s -R1000g "$url" > "$output_wrk"
31+
config_wrk="$config_wrk -R1000g $url"
1532
else
16-
echo "wrk -t50 -c1000 -d10s $url"
17-
wrk -t50 -c1000 -d10s "$url" > "$output_wrk"
33+
config_wrk="$config_wrk $url"
1834
fi
1935

36+
echo $config_wrk
37+
38+
config_wrk="$config_wrk '$url' > '$output_wrk'"
39+
eval $config_wrk
40+
2041
rps=`grep "Requests/sec:" "$output_wrk" | tr -dc '0-9.'`
2142

22-
count=5
43+
numfmt --g "$rps rps"
2344

45+
# to make a small gap between the WRK and CURL
46+
sleep 1
47+
48+
count=5
2449
total=0
2550
i=0
2651
# The for (( expr ; expr ; expr )) syntax is not available in sh, so:

benchmarks/hello_world.sh

100644100755
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,16 @@ mv "$check_file" "$check_file.old"
1818
mv "$error_file" "$error_file.old"
1919
mv "$url_file" "$url_file.old"
2020

21+
22+
phpv=`php -r 'echo phpversion();'`
23+
echo "/------- PHP $phpv -------/"
24+
2125
for fw in `echo $targets`
2226
do
2327
if [ -d "$fw" ]; then
2428
echo "/------- $fw: benchmarking -------/"
2529
echo "$fw/_benchmark/hello_world.sh"
30+
php ./libs/reset_opcache.php
2631
. "$fw/_benchmark/hello_world.sh"
2732
benchmark "$fw" "$url"
2833
fi

bin/show_results_table.php

100644100755
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44
require __DIR__ . '/../libs/build_table.php';
55

66
$results = parse_results(__DIR__ . '/../output/results.hello_world.log');
7-
//var_dump($results);
87

98
echo build_table($results);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
# clear cache
3+
bin/cake cache clear_all
4+
echo -e "done"

cakephp-4.3/_benchmark/hello_world.sh

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/sh
2-
url="$base/$fw/index.php/hello/index"
2+
url="$base/$fw/webroot/index.php/hello/index"

cakephp-4.3/_benchmark/setup.sh

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ yes|mv ./_benchmark/temp/{.,}* ./
77
# have the route & controller
88
yes|cp -r _benchmark/cakephp/* ./
99

10-
# some enhancement
10+
# some enhancements
1111
composer dump-autoload -o
12-
sudo rm -rf tmp/*
13-
composer install --no-interaction --no-dev -o
12+
composer install --no-interaction --no-dev -o
13+
rm ./webroot/.htaccess

cakephp-4.3/_benchmark/update.sh

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ composer update
44
# have the route & controller
55
yes|cp -r _benchmark/cakephp/* ./
66

7-
# some enhancement
7+
# some enhancements
88
composer dump-autoload -o
9-
sudo rm -rf tmp/*
10-
composer install --no-interaction --no-dev -o
9+
composer install --no-interaction --no-dev -o
10+
rm ./webroot/.htaccess

check.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
3+
base="http://127.0.0.1/php-frameworks-bench"
4+
5+
# cd `dirname $0`#
6+
7+
if [ $# -eq 0 ]; then
8+
# include framework list
9+
. ./list.sh
10+
export targets="$list"
11+
else
12+
export targets="${@%/}"
13+
fi
14+
15+
for fw in `echo $targets`
16+
do
17+
if [ -d "$fw" ]; then
18+
echo -n "/------- $fw: checking... "
19+
. "$fw/_benchmark/hello_world.sh"
20+
21+
url_output=$(curl -s "$url")
22+
23+
if ! [[ "$url_output" =~ ^('Hello World!')(.*)(([0-9]*):(([0-9]+([.][0-9]*)?|[.][0-9]+)):([0-9]*))$ ]]; then
24+
echo -e "error: \n$url"
25+
echo "$url_output"
26+
else
27+
echo "done."
28+
fi
29+
fi
30+
done

0 commit comments

Comments
 (0)