Skip to content

Commit

Permalink
Add PHPBench tool and first benchmark example
Browse files Browse the repository at this point in the history
  • Loading branch information
stloyd committed Oct 14, 2023
1 parent 37d509d commit ef2dca0
Show file tree
Hide file tree
Showing 10 changed files with 1,838 additions and 1 deletion.
60 changes: 60 additions & 0 deletions .github/workflows/benchmark-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Benchmark History Tag

on:
push:
branches: [ 1.x ]

jobs:
benchmark-tag:
name: "Benchmark History Tag"

runs-on: ${{ matrix.operating-system }}

strategy:
fail-fast: false
matrix:
dependencies:
- "locked"
php-version:
- "8.1"
operating-system:
- "ubuntu-latest"

steps:
- name: "Checkout"
uses: "actions/checkout@v4"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: none
tools: composer:v2
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1

- name: "Get Composer Cache Directory"
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: "Cache Composer dependencies"
uses: "actions/cache@v3"
with:
path: "${{ steps.composer-cache.outputs.dir }}"
key: "php-${{ matrix.php-version }}-locked-composer-${{ hashFiles('**/composer.lock') }}"
restore-keys: |
php-${{ matrix.php-version }}-locked-composer-
- name: "Install locked dependencies"
run: "composer install --no-interaction --no-progress"

- name: "Cache PHPBench reports"
uses: "actions/cache@v3"
with:
path: "var/phpbench"
key: "php-${{ matrix.php-version }}-phpbench"
restore-keys: |
php-${{ matrix.php-version }}-phpbench-
- name: "Benchmark Tag"
run: "composer test:benchmark -- --tag=original"
59 changes: 59 additions & 0 deletions .github/workflows/test-benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Benchmark Suite

on:
pull_request:

jobs:
benchmark:
name: "Benchmark"

runs-on: ${{ matrix.operating-system }}

strategy:
fail-fast: false
matrix:
dependencies:
- "locked"
php-version:
- "8.1"
operating-system:
- "ubuntu-latest"

steps:
- name: "Checkout"
uses: "actions/checkout@v4"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: none
tools: composer:v2
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1

- name: "Get Composer Cache Directory"
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: "Cache Composer dependencies"
uses: "actions/cache@v3"
with:
path: "${{ steps.composer-cache.outputs.dir }}"
key: "php-${{ matrix.php-version }}-locked-composer-${{ hashFiles('**/composer.lock') }}"
restore-keys: |
php-${{ matrix.php-version }}-locked-composer-
- name: "Install locked dependencies"
run: "composer install --no-interaction --no-progress"

- name: "Cache PHPBench reports"
uses: "actions/cache@v3"
with:
path: "var/phpbench"
key: "php-${{ matrix.php-version }}-phpbench"
restore-keys: |
php-${{ matrix.php-version }}-phpbench-
- name: "Benchmark"
run: "composer test:benchmark -- --ref=original"
2 changes: 1 addition & 1 deletion .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: "Get Composer Cache Directory"
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: "Cache Composer dependencies"
uses: "actions/cache@v3"
Expand Down
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@
"test": [
"tools/phpunit/vendor/bin/phpunit"
],
"test:benchmark": [
"tools/phpbench/vendor/bin/phpbench run --report=aggregate --retry-threshold=5 --iterations=10"
],
"test:mutation": [
"tools/infection/vendor/bin/infection -j2"
],
Expand Down Expand Up @@ -192,6 +195,7 @@
"composer install --working-dir=./tools/cs-fixer",
"composer install --working-dir=./tools/infection",
"composer install --working-dir=./tools/monorepo",
"composer install --working-dir=./tools/phpbench",
"composer install --working-dir=./tools/phpstan",
"composer install --working-dir=./tools/psalm",
"composer install --working-dir=./tools/phpunit",
Expand Down
7 changes: 7 additions & 0 deletions phpbench.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "./tools/phpbench/vendor/phpbench/phpbench/phpbench.schema.json",
"runner.bootstrap": "vendor/autoload.php",
"runner.path": "src/core/etl/tests/Flow/ETL/Tests/Benchmark/",
"runner.progress": "dots",
"storage.xml_storage_path": "var/phpbench"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php declare(strict_types=1);

namespace Flow\ETL\Tests\Benchmark\Example;

use function Flow\ETL\DSL\concat;
use function Flow\ETL\DSL\lit;
use function Flow\ETL\DSL\ref;
use function Flow\ETL\DSL\struct;
use Flow\ETL\DSL\CSV;
use Flow\ETL\DSL\To;
use Flow\ETL\Flow;
use Flow\ETL\GroupBy\Aggregation;
use Flow\ETL\Memory\ArrayMemory;
use PhpBench\Attributes\Revs;

final class PowerPlantBench
{
#[Revs(100)]
public function bench_aggregation() : void
{
(new Flow())
->read(CSV::from(__DIR__ . '/../../Fixtures/power-plant-daily.csv', delimiter: ';'))
->withEntry('production_kwh', ref('Produkcja(kWh)'))
->withEntry('consumption_kwh', ref('Zużycie(kWh)'))
->withEntry('date', ref('Zaktualizowany czas')->toDate('Y/m/d')->dateFormat('Y/m'))
->select(struct('date', 'production_kwh', 'consumption_kwh'))
->groupBy(ref('date'))
->aggregate(
Aggregation::avg(ref('production_kwh')),
Aggregation::avg(ref('consumption_kwh')),
Aggregation::min(ref('production_kwh')),
Aggregation::min(ref('consumption_kwh')),
Aggregation::max(ref('production_kwh')),
Aggregation::max(ref('consumption_kwh')),
Aggregation::sum(ref('production_kwh')),
Aggregation::sum(ref('consumption_kwh'))
)
->withEntry('production_kwh_avg', ref('production_kwh_avg')->round(lit(2)))
->withEntry('consumption_kwh_avg', ref('consumption_kwh_avg')->round(lit(2)))
->withEntry('production_kwh_min', ref('production_kwh_min')->round(lit(2)))
->withEntry('consumption_kwh_min', ref('consumption_kwh_min')->round(lit(2)))
->withEntry('production_kwh_max', ref('production_kwh_max')->round(lit(2)))
->withEntry('consumption_kwh_max', ref('consumption_kwh_max')->round(lit(2)))
->withEntry('production_kwh_sum', ref('production_kwh_sum')->round(lit(2)))
->withEntry('consumption_kwh_sum', ref('consumption_kwh_sum')->round(lit(2)))
->withEntry('consumption', ref('consumption_kwh_sum')->divide(ref('production_kwh_sum')))
->withEntry('consumption', ref('consumption')->multiply(lit(100))->round(lit(2)))
->withEntry('consumption', concat(ref('consumption'), lit('%')))
->write(To::memory(new ArrayMemory()))
->run();
}
}
105 changes: 105 additions & 0 deletions src/core/etl/tests/Flow/ETL/Tests/Fixtures/power-plant-daily.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
Zaktualizowany czas;Strefa czasowa;Produkcja(kWh);Zużycie(kWh);Wejście do sieci(kWh);Zakupiona energia(kWh);Ładowanie energii(kWh);Rozładowanie energii(kWh);Stosunek własny(%);Oczekiwany dochód(PLN)
2022/01/01;UTC+01:00;2.11;16.32;0.00;20.60;0.04;0.01;;
2022/01/02;UTC+01:00;9.25;18.53;0.09;18.65;2.76;0.01;;
2022/01/03;UTC+01:00;11.54;18.30;0.96;9.07;6.42;11.49;;
2022/01/04;UTC+01:00;3.84;17.04;0.09;18.00;0.07;1.89;;
2022/01/05;UTC+01:00;2.54;17.52;0.00;21.50;0.07;0.01;;
2022/01/06;UTC+01:00;15.36;20.64;0.34;14.68;8.94;6.47;;
2022/01/07;UTC+01:00;32.50;16.85;13.94;7.28;11.62;9.11;;
2022/01/08;UTC+01:00;14.10;17.21;0.49;7.70;8.11;10.51;;
2022/01/09;UTC+01:00;24.62;23.36;2.57;8.54;12.61;11.94;;
2022/01/10;UTC+01:00;2.30;14.26;0.00;18.17;0.01;0.02;;
2022/01/11;UTC+01:00;27.60;14.07;7.43;5.51;13.65;8.31;;
2022/01/12;UTC+01:00;3.41;12.92;0.26;11.28;0.15;4.83;;
2022/01/13;UTC+01:00;8.68;15.90;0.16;14.92;3.52;2.32;;
2022/01/14;UTC+01:00;2.29;12.65;0.00;16.75;0.10;0.01;;
2022/01/15;UTC+01:00;37.34;15.96;17.24;4.92;12.92;10.36;;
2022/01/16;UTC+01:00;27.97;14.10;5.22;2.24;13.88;9.49;;
2022/01/17;UTC+01:00;4.43;18.14;0.18;15.21;1.19;6.21;;
2022/01/18;UTC+01:00;10.38;15.37;0.15;15.60;4.07;0.01;;
2022/01/19;UTC+01:00;32.96;15.06;16.43;6.13;8.70;7.42;;
2022/01/20;UTC+01:00;10.25;18.96;0.56;11.16;5.81;10.30;;
2022/01/21;UTC+01:00;4.97;15.57;0.03;17.36;0.39;0.01;;
2022/01/22;UTC+01:00;2.24;19.32;0.00;23.31;0.04;0.01;;
2022/01/23;UTC+01:00;5.92;16.75;0.08;18.85;1.65;0.01;;
2022/01/24;UTC+01:00;32.84;16.45;14.02;6.28;11.94;9.67;;
2022/01/25;UTC+01:00;5.88;21.96;0.26;20.22;0.83;3.07;;
2022/01/26;UTC+01:00;6.31;16.63;0.05;17.28;0.54;0.01;;
2022/01/27;UTC+01:00;8.25;18.29;0.22;17.59;2.73;1.81;;
2022/01/28;UTC+01:00;5.15;15.44;0.02;16.95;0.29;0.01;;
2022/01/29;UTC+01:00;22.42;17.09;4.73;6.16;11.87;11.58;;
2022/01/30;UTC+01:00;5.77;18.27;0.13;18.16;0.60;1.33;;
2022/01/31;UTC+01:00;5.44;16.27;0.02;17.40;0.40;0.01;;
2022/02/01;UTC+01:00;12.88;18.20;0.24;13.58;7.21;5.54;;
2022/02/02;UTC+01:00;19.07;19.92;0.53;9.48;10.48;8.97;;
2022/02/03;UTC+01:00;13.22;17.37;0.38;11.05;5.87;5.74;;
2022/02/04;UTC+01:00;9.91;15.46;0.26;12.87;3.94;3.16;;
2022/02/05;UTC+01:00;26.89;22.63;4.36;7.41;12.16;11.29;;
2022/02/06;UTC+01:00;13.75;17.57;0.51;8.68;6.76;8.86;;
2022/02/07;UTC+01:00;10.93;19.62;0.35;16.16;3.53;2.67;;
2022/02/08;UTC+01:00;15.08;15.15;0.46;8.20;8.71;7.49;;
2022/02/09;UTC+01:00;5.80;15.84;0.07;17.42;1.01;0.01;;
2022/02/10;UTC+01:00;12.60;15.53;0.28;10.37;6.26;5.56;;
2022/02/11;UTC+01:00;5.41;18.24;0.01;19.71;0.54;0.01;;
2022/02/12;UTC+01:00;46.98;17.00;27.82;7.26;10.21;7.28;;
2022/02/13;UTC+01:00;48.16;15.11;25.65;0.46;13.31;12.03;;
2022/02/14;UTC+01:00;47.43;16.67;25.79;0.52;12.55;13.47;;
2022/02/15;UTC+01:00;36.01;16.44;13.90;1.32;13.65;13.15;;
2022/02/16;UTC+01:00;33.94;16.71;11.91;2.51;13.71;12.35;;
2022/02/17;UTC+01:00;15.46;16.48;0.70;4.81;9.39;12.83;;
2022/02/18;UTC+01:00;43.28;14.76;22.86;6.06;12.94;7.80;;
2022/02/19;UTC+01:00;30.36;29.04;3.30;4.46;14.24;18.45;;
2022/02/20;UTC+01:00;17.82;19.01;0.51;9.53;8.49;7.22;;
2022/02/21;UTC+01:00;13.49;16.91;0.28;11.11;5.87;5.03;;
2022/02/22;UTC+01:00;30.41;15.57;9.81;5.72;12.47;8.31;;
2022/02/23;UTC+01:00;23.67;16.94;2.75;2.74;13.99;13.95;;
2022/02/24;UTC+01:00;46.59;16.35;21.93;1.73;14.26;10.73;;
2022/02/25;UTC+01:00;23.62;19.87;1.58;3.73;13.31;14.03;;
2022/02/26;UTC+01:00;17.60;15.20;0.64;0.53;10.03;14.35;;
2022/02/27;UTC+01:00;31.24;22.72;4.47;6.50;14.79;10.97;;
2022/02/28;UTC+01:00;34.33;16.80;11.18;1.99;14.35;12.54;;
2022/03/01;UTC+01:00;55.53;15.43;32.04;1.37;13.78;10.98;17.49;
2022/03/02;UTC+01:00;56.20;21.69;30.95;0.68;12.72;15.04;22.30;
2022/03/03;UTC+01:00;43.20;16.29;19.61;1.98;13.79;11.04;;
2022/03/04;UTC+01:00;10.67;17.03;0.41;8.86;4.46;8.89;;
2022/03/05;UTC+01:00;15.94;16.75;0.62;9.22;8.64;7.49;;
2022/03/06;UTC+01:00;9.37;12.15;0.23;10.37;3.23;2.45;;
2022/03/07;UTC+01:00;19.50;16.57;0.39;5.88;10.74;8.97;;
2022/03/08;UTC+01:00;31.86;15.79;12.05;4.80;11.75;9.31;;
2022/03/09;UTC+01:00;21.80;20.59;0.58;2.87;11.48;14.55;;
2022/03/10;UTC+01:00;58.67;16.49;35.38;5.03;13.00;7.66;17.54;
2022/03/11;UTC+01:00;63.89;15.72;40.20;0.70;13.04;10.86;16.67;
2022/03/12;UTC+01:00;59.73;16.60;36.21;0.50;11.49;10.57;20.14;
2022/03/13;UTC+01:00;53.93;14.96;32.33;0.35;11.74;11.44;;
2022/03/14;UTC+01:00;49.76;18.19;25.71;0.58;11.88;11.92;;
2022/03/15;UTC+01:00;47.60;16.23;24.97;0.48;12.55;12.26;;
2022/03/16;UTC+01:00;44.91;14.34;22.83;0.37;13.29;11.79;;
2022/03/17;UTC+01:00;48.07;16.12;25.99;0.57;12.01;11.99;;
2022/03/18;UTC+01:00;55.92;13.65;34.26;0.40;13.25;11.38;15.04;
2022/03/19;UTC+01:00;62.05;21.45;33.25;0.42;12.95;11.72;25.54;
2022/03/20;UTC+01:00;55.95;16.06;33.24;0.47;11.53;10.89;19.98;
2022/03/21;UTC+01:00;55.32;14.53;32.65;0.56;11.70;9.56;;
2022/03/22;UTC+01:00;56.63;14.34;36.85;0.38;10.17;10.99;16.97;
2022/03/23;UTC+01:00;55.64;15.42;34.25;0.37;11.82;12.01;17.20;
2022/03/24;UTC+01:00;52.82;12.96;30.92;0.39;12.67;9.82;;
2022/03/25;UTC+01:00;56.78;20.32;32.98;0.91;10.55;12.60;23.34;
2022/03/26;UTC+01:00;53.15;21.35;28.17;0.53;13.83;16.28;20.98;
2022/03/27;UTC+01:00;58.46;18.87;31.66;4.61;13.62;7.42;22.55;
2022/03/28;UTC+01:00;56.16;14.13;35.27;0.38;12.32;11.79;15.26;
2022/03/29;UTC+01:00;33.61;15.92;10.11;0.54;12.76;11.20;;
2022/03/30;UTC+01:00;38.18;13.85;17.70;0.49;11.65;11.10;;
2022/03/31;UTC+01:00;4.73;17.02;0.15;11.90;0.01;7.05;;
2022/04/01;UTC+01:00;6.34;14.79;0.06;15.80;0.74;0.01;;
2022/04/02;UTC+01:00;2.14;14.08;0.00;18.35;0.01;0.01;;
2022/04/03;UTC+01:00;35.60;15.94;11.15;7.35;14.19;5.05;;
2022/04/04;UTC+01:00;57.02;17.41;35.12;0.52;10.47;12.01;20.05;
2022/04/05;UTC+01:00;20.52;17.49;0.90;2.11;9.42;11.87;;
2022/04/06;UTC+01:00;27.79;15.37;4.28;4.18;12.68;6.96;;
2022/04/07;UTC+01:00;49.05;12.09;30.06;0.52;10.79;9.81;;
2022/04/08;UTC+01:00;40.39;16.77;20.20;0.89;10.76;12.95;;
2022/04/09;UTC+01:00;15.97;22.11;0.46;9.09;4.83;8.90;;
2022/04/10;UTC+01:00;52.34;16.46;26.11;4.90;13.12;5.12;;
2022/04/11;UTC+01:00;44.50;14.96;24.26;0.59;10.71;11.26;;
2022/04/12;UTC+01:00;49.41;11.72;28.91;0.45;11.66;8.99;;
2022/04/13;UTC+01:00;46.09;13.40;27.01;0.55;9.66;9.85;;
2022/04/14;UTC+01:00;1.26;3.50;0.13;0.14;0.26;4.60;;
1 change: 1 addition & 0 deletions tools/phpbench/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor
10 changes: 10 additions & 0 deletions tools/phpbench/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "flow-php/etl-tools",
"description": "Flow PHP ETL - Tools",
"require-dev": {
"phpbench/phpbench": "^1.2"
},
"config": {
"allow-plugins": false
}
}
Loading

0 comments on commit ef2dca0

Please sign in to comment.