Skip to content

Commit d3cc63f

Browse files
authored
Merge pull request #6 from myaaghubi/v2.0
V2.0.0
2 parents daa05d5 + 2536a77 commit d3cc63f

File tree

72 files changed

+406
-204
lines changed

Some content is hidden

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

72 files changed

+406
-204
lines changed

README.md

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Benchmarking on components like template engines or ORM/Database libraries is ou
1818
- [Benchmarking Policy](#benchmarking-policy)
1919
- [How to Benchmark](#how-to-benchmark)
2020
- [Commands](#commands)
21+
- [Donate](#🍔-donate)
2122
- [References](#references)
2223
- [License](#license)
2324

@@ -71,17 +72,17 @@ These are my benchmarks, not yours. **I encourage you to run on your (production
7172

7273
## Benchmarking Policy
7374

74-
This is `master` branch.
75+
This is for the `main` branch.
7576

76-
* Install a framework via `composer` according to the official documentation.
77-
* Use the default configuration.
78-
* Consider minimum changes to run the benchmark.
79-
* Don't remove any components/configurations even if there be no use for them.
80-
* Have a `controller` class for the `Hello World`, considering the default template of a controller of your framework.
81-
* Turn off `debug` mode and set environment to `production` mode.
82-
* Run the general optimization in your production environment, like `--optimize-autoloader` for the composer.
77+
* Frameworks installed via `composer` according to their official documentation.
78+
* Used the default configuration.
79+
* Considering the minimum changes on frameworks to run the benchmark.
80+
* Didn't remove any components/configurations even if there is no use for them.
81+
* We have a `controller` class to get the `Hello World` for each, based on the default template of each framework.
82+
* Turned off the `debug` mode and set the environment to `production` mode.
83+
* Considered general optimization for the production environment, like `--optimize-autoloader` for the composer.
8384

84-
Some frameworks are optimized more than others, so some people may think using default configuration is not fair. The dept of optimizing a framework depends on the developer's experience too, so it's the rabbit hole and there is no point in it. I think the default configuration of frameworks is a good starting point to get ranking.
85+
Some frameworks are optimized more than others, so some people may think using default configuration is not fair. The dept of optimizing a framework depends on the experiences of the developer too, so it's the rabbit hole and there is no point in it. I think the default configuration of frameworks is a good starting point to get ranking.
8586

8687
If you find something wrong in my code, feel free to send a 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.
8788

@@ -90,23 +91,26 @@ If you find something wrong in my code, feel free to send a PR. But please note
9091

9192
If you want to have benchmarks on `PHP extension frameworks` like Phalcon, you need to install the extension first based on its own documentation.
9293

93-
1- Download & install the library into your localhost:
94+
1- Download & Setup:
9495

9596
```bash
9697
# you can put --branch vx.x
97-
$ git clone https://github.com/myaaghubi/php-frameworks-bench.git
98+
$ git clone https://github.com/myaaghubi/PHP-Frameworks-Bench.git
9899

99-
$ cd php-frameworks-bench
100+
$ cd PHP-Frameworks-Bench
100101

101102
# run the setup & follow the progress
103+
# check out benchmark.config
102104
$ bash setup.sh
103105
```
104106

105-
2- To make sure everything is ok:
107+
2- Make sure everything is ok:
106108

107109
```bash
108110
# this is optional
109111
$ bash check.sh
112+
# bash check.sh -t pure-php
113+
# /------- pure-php: checking... done.
110114
```
111115

112116
3- Run benchmarks:
@@ -117,42 +121,43 @@ $ bash benchmark.sh
117121

118122
4- Check the resuts:
119123

120-
<http://localhost/php-frameworks-bench/>
124+
<http://localhost/PHP-Frameworks-Bench/>
121125

122126

123127
## Commands
124128

125129
```bash
126-
# composer update for each framework
130+
# run composer update for frameworks
127131
$ bash update.sh
128132

129133
# to clean them all
130134
# trouble? run it then
131-
# you can use setup.sh
135+
# you can use setup.sh again
132136
$ bash clean.sh
133137

134138
# clear the cache of frameworks
135139
$ bash clear-cache.sh
136140

137-
# show the table of last benchmark
141+
# show the results of the last benchmark
138142
$ bash show-table.sh
139143
```
140144

141-
To specify the frameworks, put them after each command:
145+
To specify the frameworks, put them with `-t ...` after each command:
142146

143147
```bash
144148
# supported for `setup.sh`, `benchmark.sh`, `update.sh`, `clean.sh`, and `clear-cache.sh`
145-
$ bash benchmark.sh laravel-9.1/ slim-4.10/ fatfree-3.8.0/
149+
# bash benchmarks.sh --help -h
150+
$ bash benchmark.sh -t laravel-9.1/ slim-4.10/ fatfree-3.8.0/ ...
146151
...
147152
```
148153

149154

150-
## :hamburger: Donate
151-
Don't forget to donate if you used it :coffee: :beer: :cocktail: :hamburger:
155+
## 🍔 Donate
156+
Don't forget to donate if you find it useful ☕ 🍺 🍸 🍔
152157

153158
ETH: 0x0ADd51D6855d2DF11BB5F331A3fa345c67a863b2
154159

155-
![Ethereum](screenshots/ethereum.png?raw=true "Ethereum")
160+
![Ethereum](screenshots/ethereum.jpg?raw=true "Ethereum")
156161

157162
## References
158163
Note: This project is based on

base/_functions.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ benchmark () {
55
output="output/$fw.output"
66

77
# check out the appropriate response is reachable
8-
url_status=$(bash check.sh "$fw")
8+
url_status=$(bash check.sh -t "$fw")
99

1010
# find 'done'
1111
status=${url_status%%done*}
@@ -20,7 +20,7 @@ benchmark () {
2020
return 1
2121
fi
2222

23-
config_wrk="wrk -t50 -c1000 -d60s"
23+
config_wrk="wrk -t${threads} -c${connections} -d${duration}s"
2424

2525
# is it wsl!?
2626
# if you're using wsl, it's necessary to put -R (--rate)
@@ -38,9 +38,10 @@ benchmark () {
3838
config_wrk="$config_wrk '$url' > '$output_wrk'"
3939
eval $config_wrk
4040

41-
rps=`grep "Requests/sec:" "$output_wrk" | tr -dc '0-9.'`
41+
rps=`grep "Requests/sec:" "$output_wrk" | tr -cd '0-9.'`
4242

43-
numfmt --g "$rps rps"
43+
echo "rps: "
44+
numfmt --g "$rps"
4445

4546
# to make a small gap between the WRK and CURL
4647
sleep 1
@@ -51,12 +52,12 @@ benchmark () {
5152
# The for (( expr ; expr ; expr )) syntax is not available in sh, so:
5253
while [ $i -lt $count ]
5354
do
54-
curl "$url" > "$output"
55+
curl -sS "$url" > "$output"
5556
t=`tail -1 "$output" | cut -f 2 -d ':'`
56-
total=`php ./base/sum_ms.php $t $total`
57+
total=`php ./libs/sum_ms.php $t $total`
5758
i=$(( $i + 1 ))
5859
done
59-
time=`php ./base/avg_ms.php $total $count`
60+
time=`php ./libs/avg_ms.php $total $count`
6061

6162

6263
# get memory and file
@@ -69,7 +70,6 @@ benchmark () {
6970
grep "Document Length:" "$output_wrk" >> "$check_file"
7071
grep "Failed requests:" "$output_wrk" >> "$check_file"
7172
grep 'Hello World!' "$output" >> "$check_file"
72-
echo "---" >> "$check_file"
7373

7474
# check errors
7575
touch "$error_file"

base/hello_world.sh

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
cd `dirname $0`
44
. ./_functions.sh
5+
. ../benchmark.config
56

6-
base="$1"
77
bm_name=`basename $0 .sh`
88

99
results_file="output/results.$bm_name.log"
@@ -13,22 +13,81 @@ url_file="output/urls.log"
1313

1414
cd ..
1515

16-
mv "$results_file" "$results_file.old"
17-
mv "$check_file" "$check_file.old"
18-
mv "$error_file" "$error_file.old"
19-
mv "$url_file" "$url_file.old"
16+
if [ -f "$results_file" ]; then
17+
echo "moving $results_file to $results_file.old"
18+
mv "$results_file" "$results_file.old"
19+
fi
20+
21+
if [ -f "$check_file" ]; then
22+
echo "moving $check_file to $check_file.old"
23+
mv "$check_file" "$check_file.old"
24+
fi
25+
26+
if [ -f "$error_file" ]; then
27+
echo "moving $error_file to $error_file.old"
28+
mv "$error_file" "$error_file.old"
29+
fi
30+
31+
if [ -f "$url_file" ]; then
32+
echo "moving $url_file to $url_file.old"
33+
mv "$url_file" "$url_file.old"
34+
fi
2035

2136

2237
phpv=`php -r 'echo phpversion();'`
2338
echo "/------- PHP $phpv -------/"
2439

25-
for fw in `echo $targets`
40+
for fw in `echo $param_targets`
2641
do
2742
if [ -d "$fw" ]; then
28-
echo "/------- $fw: benchmarking -------/"
29-
echo "$fw/_benchmark/hello_world.sh"
43+
echo "/------- $fw -------/"
44+
45+
# read -p "Continue to $fw (y/n)?" choice
46+
# case "$choice" in
47+
# y|Y ) echo "yes";;
48+
# n|N ) echo "no";;
49+
# * ) echo "invalid";;
50+
# esac
51+
# if [ "$choice" = "n" ] || [ "$choice" = "N" ]; then
52+
# continue
53+
# fi
54+
55+
if [ "$param_clean" = true ]; then
56+
bash clean.sh
57+
bash setup.sh "$fw"
58+
fi
59+
60+
# read -p "Continue to benchmark (y/n)?" choice
61+
# case "$choice" in
62+
# y|Y ) echo "yes";;
63+
# * ) echo "invalid";;
64+
# esac
65+
# if [ "$choice" = "n" ] || [ "$choice" = "N" ]; then
66+
# continue
67+
# fi
68+
69+
# reset the opcache
3070
php ./libs/reset_opcache.php
71+
72+
if [ "$param_restart_apache" = true ]; then
73+
echo 'systemctl restart apache2'
74+
sudo systemctl restart apache2
75+
fi
76+
77+
if [ "$param_restart_nginx" = true ]; then
78+
echo 'systemctl restart nginx'
79+
sudo systemctl restart nginx
80+
fi
81+
82+
# a small gap between composer, reset_opcache, webserver restarted and benchmark
83+
sleep 2
84+
85+
# get the hello world link
3186
. "$fw/_benchmark/hello_world.sh"
87+
88+
echo "/------- $fw: benchmarking -------/"
89+
90+
# run the benchmark
3291
benchmark "$fw" "$url"
3392
fi
3493
done

base/option_target.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/sh
2+
3+
if [ ! `which php` ]; then
4+
echo "php not found."
5+
exit 1;
6+
fi
7+
8+
function showHelp()
9+
{
10+
cat << HEREDOC
11+
12+
Usage: bash check.sh [-t pure-php/ slim-*]
13+
14+
Optional Arguments:
15+
-h, --help Show this help message and exit
16+
-t, --target Specify your target framework/s for benchmarking
17+
Separate them via space.
18+
19+
HEREDOC
20+
}
21+
22+
export param_targets="$frameworks_list"
23+
24+
oldIFS="$IFS"
25+
paramsin="${@%/}"
26+
IFS='()'
27+
# ${paramsin%%*( )} not a good idea
28+
paramsin=(`php ./libs/trim.php "r" "${paramsin}"`)
29+
IFS=';'
30+
params=(`php ./libs/strreplace.php " -" ";-" " ${paramsin}"`)
31+
IFS=$oldIFS
32+
33+
for option in "${params[@]}"
34+
do
35+
case "$option" in
36+
-t*|--target*)
37+
arg_=${option//--target /}
38+
arg_=${arg_//-t /}
39+
if [ ${#arg_} -ge 5 ]; then
40+
param_targets="$arg_"
41+
fi
42+
;;
43+
-h|--help)
44+
showHelp;
45+
;;
46+
""|" ")
47+
;;
48+
*)
49+
echo "\"${option}\" not available"
50+
exit 1
51+
;;
52+
esac
53+
done

bin/show_fw_array.sh renamed to base/show_fw_array.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
cd `dirname $0`
44
cd ..
55

6+
. ../benchmark.config
7+
68
# include framework list
7-
. ./list.sh
8-
targets="$list"
9+
targets="$frameworks_list"
910

1011
echo '['
1112

benchmark.config

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# base url
2+
base="http://127.0.0.1/PHP-Frameworks-Bench"
3+
4+
# 30-3000
5+
# higher duration is better to get more reliable results
6+
duration=60
7+
8+
# for a high-end host you may need to put
9+
# a higher number
10+
threads=50
11+
12+
# consider your webservers configuration
13+
# max live connections
14+
connections=500
15+
16+
# Frameworks list
17+
# Sorted alphabetically
18+
frameworks_list="
19+
cakephp-4.3
20+
codeigniter-4.1
21+
fastroute-1.3
22+
fatfree-3.8.0
23+
frameworkx-dev
24+
fuelphp-1.9
25+
laminas-2.0.x.dev
26+
laravel-9.1
27+
leaf-3.0
28+
lumen-9.0
29+
phroute-2.2
30+
pure-php
31+
siler-1.7.9
32+
silex-2.3
33+
slim-3.12
34+
slim-4.10
35+
symfony-5.4
36+
symfony-6.0
37+
ubiquity-2.4.x.dev
38+
yii-2.0-basic
39+
"

0 commit comments

Comments
 (0)