Skip to content

Commit

Permalink
Merge pull request #6 from myaaghubi/v2.0
Browse files Browse the repository at this point in the history
V2.0.0
  • Loading branch information
myaaghubi authored May 13, 2023
2 parents daa05d5 + 2536a77 commit d3cc63f
Show file tree
Hide file tree
Showing 72 changed files with 406 additions and 204 deletions.
49 changes: 27 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Benchmarking on components like template engines or ORM/Database libraries is ou
- [Benchmarking Policy](#benchmarking-policy)
- [How to Benchmark](#how-to-benchmark)
- [Commands](#commands)
- [Donate](#🍔-donate)
- [References](#references)
- [License](#license)

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

## Benchmarking Policy

This is `master` branch.
This is for the `main` branch.

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

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.
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.

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.

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

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

1- Download & install the library into your localhost:
1- Download & Setup:

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

$ cd php-frameworks-bench
$ cd PHP-Frameworks-Bench

# run the setup & follow the progress
# check out benchmark.config
$ bash setup.sh
```

2- To make sure everything is ok:
2- Make sure everything is ok:

```bash
# this is optional
$ bash check.sh
# bash check.sh -t pure-php
# /------- pure-php: checking... done.
```

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

4- Check the resuts:

<http://localhost/php-frameworks-bench/>
<http://localhost/PHP-Frameworks-Bench/>


## Commands

```bash
# composer update for each framework
# run composer update for frameworks
$ bash update.sh

# to clean them all
# trouble? run it then
# you can use setup.sh
# you can use setup.sh again
$ bash clean.sh

# clear the cache of frameworks
$ bash clear-cache.sh

# show the table of last benchmark
# show the results of the last benchmark
$ bash show-table.sh
```

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

```bash
# supported for `setup.sh`, `benchmark.sh`, `update.sh`, `clean.sh`, and `clear-cache.sh`
$ bash benchmark.sh laravel-9.1/ slim-4.10/ fatfree-3.8.0/
# bash benchmarks.sh --help -h
$ bash benchmark.sh -t laravel-9.1/ slim-4.10/ fatfree-3.8.0/ ...
...
```


## :hamburger: Donate
Don't forget to donate if you used it :coffee: :beer: :cocktail: :hamburger:
## 🍔 Donate
Don't forget to donate if you find it useful ☕ 🍺 🍸 🍔

ETH: 0x0ADd51D6855d2DF11BB5F331A3fa345c67a863b2

![Ethereum](screenshots/ethereum.png?raw=true "Ethereum")
![Ethereum](screenshots/ethereum.jpg?raw=true "Ethereum")

## References
Note: This project is based on
Expand Down
16 changes: 8 additions & 8 deletions base/_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ benchmark () {
output="output/$fw.output"

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

# find 'done'
status=${url_status%%done*}
Expand All @@ -20,7 +20,7 @@ benchmark () {
return 1
fi

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

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

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

numfmt --g "$rps rps"
echo "rps: "
numfmt --g "$rps"

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


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

# check errors
touch "$error_file"
Expand Down
75 changes: 67 additions & 8 deletions base/hello_world.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

cd `dirname $0`
. ./_functions.sh
. ../benchmark.config

base="$1"
bm_name=`basename $0 .sh`

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

cd ..

mv "$results_file" "$results_file.old"
mv "$check_file" "$check_file.old"
mv "$error_file" "$error_file.old"
mv "$url_file" "$url_file.old"
if [ -f "$results_file" ]; then
echo "moving $results_file to $results_file.old"
mv "$results_file" "$results_file.old"
fi

if [ -f "$check_file" ]; then
echo "moving $check_file to $check_file.old"
mv "$check_file" "$check_file.old"
fi

if [ -f "$error_file" ]; then
echo "moving $error_file to $error_file.old"
mv "$error_file" "$error_file.old"
fi

if [ -f "$url_file" ]; then
echo "moving $url_file to $url_file.old"
mv "$url_file" "$url_file.old"
fi


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

for fw in `echo $targets`
for fw in `echo $param_targets`
do
if [ -d "$fw" ]; then
echo "/------- $fw: benchmarking -------/"
echo "$fw/_benchmark/hello_world.sh"
echo "/------- $fw -------/"

# read -p "Continue to $fw (y/n)?" choice
# case "$choice" in
# y|Y ) echo "yes";;
# n|N ) echo "no";;
# * ) echo "invalid";;
# esac
# if [ "$choice" = "n" ] || [ "$choice" = "N" ]; then
# continue
# fi

if [ "$param_clean" = true ]; then
bash clean.sh
bash setup.sh "$fw"
fi

# read -p "Continue to benchmark (y/n)?" choice
# case "$choice" in
# y|Y ) echo "yes";;
# * ) echo "invalid";;
# esac
# if [ "$choice" = "n" ] || [ "$choice" = "N" ]; then
# continue
# fi

# reset the opcache
php ./libs/reset_opcache.php

if [ "$param_restart_apache" = true ]; then
echo 'systemctl restart apache2'
sudo systemctl restart apache2
fi

if [ "$param_restart_nginx" = true ]; then
echo 'systemctl restart nginx'
sudo systemctl restart nginx
fi

# a small gap between composer, reset_opcache, webserver restarted and benchmark
sleep 2

# get the hello world link
. "$fw/_benchmark/hello_world.sh"

echo "/------- $fw: benchmarking -------/"

# run the benchmark
benchmark "$fw" "$url"
fi
done
Expand Down
53 changes: 53 additions & 0 deletions base/option_target.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/sh

if [ ! `which php` ]; then
echo "php not found."
exit 1;
fi

function showHelp()
{
cat << HEREDOC
Usage: bash check.sh [-t pure-php/ slim-*]
Optional Arguments:
-h, --help Show this help message and exit
-t, --target Specify your target framework/s for benchmarking
Separate them via space.
HEREDOC
}

export param_targets="$frameworks_list"

oldIFS="$IFS"
paramsin="${@%/}"
IFS='()'
# ${paramsin%%*( )} not a good idea
paramsin=(`php ./libs/trim.php "r" "${paramsin}"`)
IFS=';'
params=(`php ./libs/strreplace.php " -" ";-" " ${paramsin}"`)
IFS=$oldIFS

for option in "${params[@]}"
do
case "$option" in
-t*|--target*)
arg_=${option//--target /}
arg_=${arg_//-t /}
if [ ${#arg_} -ge 5 ]; then
param_targets="$arg_"
fi
;;
-h|--help)
showHelp;
;;
""|" ")
;;
*)
echo "\"${option}\" not available"
exit 1
;;
esac
done
5 changes: 3 additions & 2 deletions bin/show_fw_array.sh → base/show_fw_array.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
cd `dirname $0`
cd ..

. ../benchmark.config

# include framework list
. ./list.sh
targets="$list"
targets="$frameworks_list"

echo '['

Expand Down
39 changes: 39 additions & 0 deletions benchmark.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# base url
base="http://127.0.0.1/PHP-Frameworks-Bench"

# 30-3000
# higher duration is better to get more reliable results
duration=60

# for a high-end host you may need to put
# a higher number
threads=50

# consider your webservers configuration
# max live connections
connections=500

# Frameworks list
# Sorted alphabetically
frameworks_list="
cakephp-4.3
codeigniter-4.1
fastroute-1.3
fatfree-3.8.0
frameworkx-dev
fuelphp-1.9
laminas-2.0.x.dev
laravel-9.1
leaf-3.0
lumen-9.0
phroute-2.2
pure-php
siler-1.7.9
silex-2.3
slim-3.12
slim-4.10
symfony-5.4
symfony-6.0
ubiquity-2.4.x.dev
yii-2.0-basic
"
Loading

0 comments on commit d3cc63f

Please sign in to comment.