Skip to content

Commit 5660d41

Browse files
committed
v2.0 initial commit
1 parent 43437ac commit 5660d41

File tree

12 files changed

+193
-26
lines changed

12 files changed

+193
-26
lines changed

base/_functions.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 48 additions & 4 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"
@@ -22,13 +22,57 @@ mv "$url_file" "$url_file.old"
2222
phpv=`php -r 'echo phpversion();'`
2323
echo "/------- PHP $phpv -------/"
2424

25-
for fw in `echo $targets`
25+
for fw in `echo $param_targets`
2626
do
2727
if [ -d "$fw" ]; then
28-
echo "/------- $fw: benchmarking -------/"
29-
echo "$fw/_benchmark/hello_world.sh"
28+
echo "/------- $fw -------/"
29+
30+
# read -p "Continue to $fw (y/n)?" choice
31+
# case "$choice" in
32+
# y|Y ) echo "yes";;
33+
# n|N ) echo "no";;
34+
# * ) echo "invalid";;
35+
# esac
36+
# if [ "$choice" = "n" ] || [ "$choice" = "N" ]; then
37+
# continue
38+
# fi
39+
40+
if [ "$param_clean" = true ]; then
41+
bash clean.sh
42+
bash setup.sh "$fw"
43+
fi
44+
45+
# read -p "Continue to benchmark (y/n)?" choice
46+
# case "$choice" in
47+
# y|Y ) echo "yes";;
48+
# * ) echo "invalid";;
49+
# esac
50+
# if [ "$choice" = "n" ] || [ "$choice" = "N" ]; then
51+
# continue
52+
# fi
53+
54+
# reset the opcache
3055
php ./libs/reset_opcache.php
56+
57+
if [ "$param_restart_apache" = true ]; then
58+
echo 'systemctl restart apache2'
59+
sudo systemctl restart apache2
60+
fi
61+
62+
if [ "$param_restart_nginx" = true ]; then
63+
echo 'systemctl restart nginx'
64+
sudo systemctl restart nginx
65+
fi
66+
67+
# a small gap between composer, reset_opcache, webserver restarted and benchmark
68+
sleep 2
69+
70+
# get the hello world link
3171
. "$fw/_benchmark/hello_world.sh"
72+
73+
echo "/------- $fw: benchmarking -------/"
74+
75+
# run the benchmark
3276
benchmark "$fw" "$url"
3377
fi
3478
done

base/show_fw_array.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
3+
cd `dirname $0`
4+
cd ..
5+
6+
# include framework list
7+
. ./list.sh
8+
targets="$list"
9+
10+
echo '['
11+
12+
for fw in $targets
13+
do
14+
if [ -d "$fw" ]; then
15+
echo "\t'$fw',"
16+
fi
17+
done
18+
19+
echo ']'

benchmark.config

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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=300
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

benchmark.sh

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,74 @@
11
#!/bin/sh
22

3+
if [ ! `which php` ]; then
4+
echo "php not found."
5+
exit 1;
6+
fi
7+
38
if [ ! `which wrk` ]; then
4-
echo "wrk not found."
9+
echo "WRK not found."
510
exit 1;
611
fi
712

813
if [ ! `which curl` ]; then
9-
echo "curl not found."
14+
echo "CURL not found."
1015
exit 1;
1116
fi
1217

13-
base="http://127.0.0.1/php-frameworks-bench"
18+
function showHelp()
19+
{
20+
cat << HEREDOC
1421
15-
if [ $# -eq 0 ]; then
16-
# include frameworks list
17-
. ./list.sh
18-
export targets="$list"
19-
else
20-
export targets="${@%/}"
21-
fi
22+
Usage: bash benchmark.sh [-c] [-rapache] [-t pure-php laravel-10]
23+
24+
Optional Arguments:
25+
-c, --clean NUM Clean all frameworks and install the target framework -fresh install- before benchmark.
26+
-h, --help Show this help message and exit
27+
-rapache, --restart-apache Restart apache "sudo systemctl restart apache2" before each benchmark.
28+
-rnginx, --restart-nginx Restart apache "sudo systemctl restart nginx" before each benchmark.
29+
-t, --targets Specify your target frameworks for benchmarking.
30+
31+
HEREDOC
32+
}
33+
34+
. ./list.sh
35+
export param_targets="$list"
36+
export param_clean=false
37+
export param_restart_apache=false
38+
export param_restart_nginx=false
39+
40+
insputs=" ${@%/}"
41+
IFS=';'
42+
params=(`php ./libs/strreplace.php " -" ";-" " ${insputs}"`)
2243

23-
cd base
44+
for option in "${params[@]}"
45+
do
46+
case "$option" in
47+
-c|--clean)
48+
param_clean=true
49+
;;
50+
-rapache|--restart-apache)
51+
param_restart_apache=true
52+
;;
53+
-rnginx|--restart-nginx)
54+
param_restart_nginx=true
55+
;;
56+
-t*|--targets*)
57+
arg_=${option//--targets /}
58+
arg_=${arg_//-t /}
59+
param_targets="$arg_"
60+
;;
61+
-h|--help)
62+
showHelp;
63+
;;
64+
" ")
65+
;;
66+
*)
67+
echo "${option} not available"
68+
;;
69+
esac
70+
done
2471

25-
sh hello_world.sh "$base"
72+
sh ./base/hello_world.sh
2673

27-
php ../bin/show_results_table.php
74+
php ./libs/show_results_table.php

index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
<hr>
8888

8989
<footer>
90-
<p style="text-align: right">This page is a part of <a href="https://github.com/myaghobi/php-frameworks-bench">php-frameworks-bench</a>.</p>
90+
<p style="text-align: right">This page is a part of <a href="https://github.com/myaaghubi/PHP-Frameworks-Bench">PHP-Frameworks-Bench</a>.</p>
9191
</footer>
9292
</body>
9393
</html>
File renamed without changes.

libs/show_comparison_table.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
require __DIR__ . '/../libs/parse_results.php';
4+
require __DIR__ . '/../libs/build_table.php';
5+
require __DIR__ . '/../libs/recalc_relative.php';
6+
7+
$list = [
8+
'cake-4.2',
9+
'symfony-5.3.9',
10+
'laravel-8.6.2',
11+
];
12+
13+
system('git checkout master');
14+
$results_master = parse_results(__DIR__ . '/../output/results.hello_world.log');
15+
system('git checkout optimize');
16+
$results_optimize = parse_results(__DIR__ . '/../output/results.hello_world.log');
17+
//var_dump($results_master, $results_optimize);
18+
19+
$is_fisrt = true;
20+
foreach ($list as $fw) {
21+
$results = [];
22+
$results[$fw] = $results_master[$fw];
23+
$results[$fw . ' (*)'] = $results_optimize[$fw];
24+
25+
$results = recalc_relative($results);
26+
echo build_table($results, $is_fisrt);
27+
$is_fisrt = false;
28+
}

libs/show_results_table.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
require __DIR__ . '/../libs/parse_results.php';
4+
require __DIR__ . '/../libs/build_table.php';
5+
6+
$results = parse_results(__DIR__ . '/../output/results.hello_world.log');
7+
8+
echo build_table($results);

libs/strreplace.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
$search = $argv[1];
4+
$replace = $argv[2];
5+
$string = $argv[3];
6+
7+
echo str_replace($search, $replace, $string);

0 commit comments

Comments
 (0)