From a92962020fe84ed19d1a5097b162eef57c0961e5 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Sun, 29 Oct 2023 20:34:17 +0100 Subject: [PATCH] Simplify `Rows::drop()` method (#666) * Simplify `Rows::drop()` method * Rework benchmark scripts in `composer.json` * Fixed benchmark names --------- Co-authored-by: Norbert Orzechowicz <1921950+norberttech@users.noreply.github.com> --- .github/workflows/test-benchmark.yml | 8 ++++---- composer.json | 17 ++++++++++++++++- src/core/etl/src/Flow/ETL/Rows.php | 8 +------- .../Flow/ETL/Tests/Benchmark/RowsBench.php | 10 +++++++++- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test-benchmark.yml b/.github/workflows/test-benchmark.yml index b329aaad8..0dbce8259 100644 --- a/.github/workflows/test-benchmark.yml +++ b/.github/workflows/test-benchmark.yml @@ -81,7 +81,7 @@ jobs: echo '
Extractors' echo ' ' echo '```shell' - composer test:benchmark -- --ref=1.x --progress=none --group=extractor + composer test:benchmark:extractor -- --ref=1.x --progress=none echo '```' echo ' ' echo '
' @@ -89,7 +89,7 @@ jobs: echo '
Transformers' echo ' ' echo '```shell' - composer test:benchmark -- --ref=1.x --progress=none --group=transformer + composer test:benchmark:transformer -- --ref=1.x --progress=none echo '```' echo ' ' echo '
' @@ -97,7 +97,7 @@ jobs: echo '
Loaders' echo ' ' echo '```shell' - composer test:benchmark -- --ref=1.x --progress=none --group=loader + composer test:benchmark:loader -- --ref=1.x --progress=none echo '```' echo ' ' echo '
' @@ -105,7 +105,7 @@ jobs: echo '
Building Blocks' echo ' ' echo '```shell' - composer test:benchmark -- --ref=1.x --progress=none --group=building_blocks + composer test:benchmark:building_blocks -- --ref=1.x --progress=none echo '```' echo ' ' echo '
' diff --git a/composer.json b/composer.json index dac1be70e..08282aec9 100644 --- a/composer.json +++ b/composer.json @@ -169,7 +169,22 @@ "tools/phpunit/vendor/bin/phpunit" ], "test:benchmark": [ - "tools/phpbench/vendor/bin/phpbench run --report=flow-report" + "@test:benchmark:building_blocks", + "@test:benchmark:extractor", + "@test:benchmark:loader,", + "@test:benchmark:transformer" + ], + "test:benchmark:building_blocks": [ + "tools/phpbench/vendor/bin/phpbench run --report=flow-report --group=building_blocks" + ], + "test:benchmark:extractor": [ + "tools/phpbench/vendor/bin/phpbench run --report=flow-report --group=extractor" + ], + "test:benchmark:loader": [ + "tools/phpbench/vendor/bin/phpbench run --report=flow-report --group=loader" + ], + "test:benchmark:transformer": [ + "tools/phpbench/vendor/bin/phpbench run --report=flow-report --group=transformer" ], "test:mutation": [ "tools/infection/vendor/bin/infection -j2" diff --git a/src/core/etl/src/Flow/ETL/Rows.php b/src/core/etl/src/Flow/ETL/Rows.php index 8d912619e..aad3c797d 100644 --- a/src/core/etl/src/Flow/ETL/Rows.php +++ b/src/core/etl/src/Flow/ETL/Rows.php @@ -129,13 +129,7 @@ public function diffRight(self $rows) : self public function drop(int $size) : self { - $rows = $this->rows; - - for ($i = 0; $i < $size; $i++) { - \array_shift($rows); - } - - return new self(...$rows); + return new self(...\array_slice($this->rows, $size)); } public function dropRight(int $size) : self diff --git a/src/core/etl/tests/Flow/ETL/Tests/Benchmark/RowsBench.php b/src/core/etl/tests/Flow/ETL/Tests/Benchmark/RowsBench.php index 2392de72b..cfa2c6f0c 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Benchmark/RowsBench.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Benchmark/RowsBench.php @@ -25,10 +25,18 @@ public function __construct() } #[Revs(5)] - public function bench_chunk_10() : void + public function bench_chunk_10_on_10k() : void { foreach ($this->rows->chunks(10) as $chunk) { } } + + #[Revs(5)] + public function bench_drop_100_on_10k() : void + { + foreach ($this->rows->drop(100) as $chunk) { + + } + } }