Skip to content

Commit

Permalink
Added output of benchmark tests into github step summary (#601)
Browse files Browse the repository at this point in the history
* Added output of benchmark tests into github step summary

* Reworked benchmarks execution

* Fixed extractors benchmarks

* Fixed failing tests

* Replaced iterator_to_array with foreach in benchmarks

* Fixed benchmarks summary pages markdown

* Workflow summary formatting adjustments
  • Loading branch information
norberttech authored Oct 16, 2023
1 parent 681571c commit 314b941
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 83 deletions.
16 changes: 7 additions & 9 deletions .github/workflows/benchmark-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,12 @@ jobs:
restore-keys: |
php-${{ matrix.php-version }}-${{ env.PHPBENCH_TAG }}-phpbench-
- name: Adding main headline
run: |
echo '# Flow PHP - Benchmark - ${{ env.PHPBENCH_TAG }}' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: "Benchmark"
run: "composer test:benchmark -- --tag=${{ env.PHPBENCH_TAG }} --progress=none >> $GITHUB_STEP_SUMMARY"

- name: Adding footer
run: |
echo '```' >> $GITHUB_STEP_SUMMARY
echo '# Flow PHP - Benchmark - ${{ env.PHPBENCH_TAG }}' >> $GITHUB_STEP_SUMMARY
echo ' ' >> $GITHUB_STEP_SUMMARY
echo '---' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
composer test:benchmark -- --tag=${{ env.PHPBENCH_TAG }} --progress=none >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
42 changes: 38 additions & 4 deletions .github/workflows/test-benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Benchmark Suite
on:
pull_request:
paths:
- '.github/workflows/**'
- 'src/adapter/**'
- 'src/core/**'
- 'src/lib/**'
Expand Down Expand Up @@ -57,9 +58,42 @@ jobs:
uses: "actions/cache@v3"
with:
path: "var/phpbench"
key: "php-${{ matrix.php-version }}-phpbench"
key: "php-${{ matrix.php-version }}-1.x-phpbench"
restore-keys: |
php-${{ matrix.php-version }}-phpbench-
php-${{ matrix.php-version }}-1.x-phpbench-
- name: "Benchmark"
run: "composer test:benchmark -- --ref=original --progress=plain"
- name: Adding main headline
run: |
echo '# Flow PHP - Benchmark' >> $GITHUB_STEP_SUMMARY
echo ' ' >> $GITHUB_STEP_SUMMARY
echo '---' >> $GITHUB_STEP_SUMMARY
- name: "Benchmark Extractors"
run: |
echo ' ' >> $GITHUB_STEP_SUMMARY
echo '## Extractors' >> $GITHUB_STEP_SUMMARY
echo ' ' >> $GITHUB_STEP_SUMMARY
echo '---' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
composer test:benchmark -- --ref=1.x --progress=none --group=extractor >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: "Benchmark Transformers"
run: |
echo ' ' >> $GITHUB_STEP_SUMMARY
echo '## Transformers' >> $GITHUB_STEP_SUMMARY
echo ' ' >> $GITHUB_STEP_SUMMARY
echo '---' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
composer test:benchmark -- --ref=1.x --progress=none --group=transformer >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: "Benchmark Entry Factories"
run: |
echo ' ' >> $GITHUB_STEP_SUMMARY
echo '## Entry Factory' >> $GITHUB_STEP_SUMMARY
echo ' ' >> $GITHUB_STEP_SUMMARY
echo '---' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
composer test:benchmark -- --ref=1.x --progress=none --group=entry_factory >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

namespace Flow\ETL\Adapter\Avro\Tests\Benchmark;

use Flow\ETL\Config;
use Flow\ETL\DSL\Avro;
use Flow\ETL\FlowContext;
use PhpBench\Attributes\Groups;
use PhpBench\Attributes\Iterations;
use PhpBench\Attributes\Revs;

#[Iterations(5)]
#[Iterations(3)]
#[Groups(['extractor'])]
final class AvroExtractorBench
{
#[Revs(1000)]
public function bench_extract() : void
#[Revs(5)]
public function bench_extract_10k() : void
{
Avro::from(__DIR__ . '/../Fixtures/orders_flow.avro');
foreach (Avro::from(__DIR__ . '/../Fixtures/orders_flow.avro')->extract(new FlowContext(Config::default())) as $rows) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

namespace Flow\ETL\Adapter\CSV\Tests\Benchmark;

use Flow\ETL\Config;
use Flow\ETL\DSL\CSV;
use Flow\ETL\FlowContext;
use PhpBench\Attributes\Groups;
use PhpBench\Attributes\Iterations;
use PhpBench\Attributes\Revs;

#[Iterations(5)]
#[Iterations(3)]
#[Groups(['extractor'])]
final class CSVExtractorBench
{
#[Revs(1000)]
public function bench_extract() : void
#[Revs(5)]
public function bench_extract_10k() : void
{
CSV::from(__DIR__ . '/../Fixtures/orders_flow.csv');
foreach (CSV::from(__DIR__ . '/../Fixtures/orders_flow.csv')->extract(new FlowContext(Config::default())) as $rows) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

namespace Flow\ETL\Adapter\JSON\Tests\Benchmark;

use Flow\ETL\Config;
use Flow\ETL\DSL\Json;
use Flow\ETL\FlowContext;
use PhpBench\Attributes\Groups;
use PhpBench\Attributes\Iterations;
use PhpBench\Attributes\Revs;

#[Iterations(5)]
#[Iterations(3)]
#[Groups(['extractor'])]
final class JsonExtractorBench
{
#[Revs(1000)]
public function bench_extract() : void
#[Revs(5)]
public function bench_extract_10k() : void
{
Json::from(__DIR__ . '/../Fixtures/orders_flow.json');
foreach (Json::from(__DIR__ . '/../Fixtures/orders_flow.json')->extract(new FlowContext(Config::default())) as $rows) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

namespace Flow\ETL\Adapter\Parquet\Tests\Benchmark;

use Flow\ETL\Config;
use Flow\ETL\DSL\Parquet;
use Flow\ETL\FlowContext;
use PhpBench\Attributes\Groups;
use PhpBench\Attributes\Iterations;
use PhpBench\Attributes\Revs;

#[Iterations(5)]
#[Iterations(3)]
#[Groups(['extractor'])]
final class ParquetExtractorBench
{
#[Revs(1000)]
public function bench_extract() : void
#[Revs(5)]
public function bench_extract_10k() : void
{
Parquet::from(__DIR__ . '/../Fixtures/orders_flow.parquet');
foreach (Parquet::from(__DIR__ . '/../Fixtures/orders_flow.parquet')->extract(new FlowContext(Config::default())) as $rows) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

namespace Flow\ETL\Adapter\Text\Tests\Benchmark;

use Flow\ETL\Config;
use Flow\ETL\DSL\Text;
use Flow\ETL\FlowContext;
use PhpBench\Attributes\Groups;
use PhpBench\Attributes\Iterations;
use PhpBench\Attributes\Revs;

#[Iterations(5)]
#[Iterations(3)]
#[Groups(['extractor'])]
final class TextExtractorBench
{
#[Revs(1000)]
#[Revs(5)]
public function bench_extract() : void
{
Text::from(__DIR__ . '/../Fixtures/annual-enterprise-survey-2019-financial-year-provisional-csv.csv');
foreach (Text::from(__DIR__ . '/../Fixtures/annual-enterprise-survey-2019-financial-year-provisional-csv.csv')->extract(new FlowContext(Config::default())) as $rows) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

namespace Flow\ETL\Adapter\XML\Tests\Benchmark;

use Flow\ETL\Config;
use Flow\ETL\DSL\XML;
use Flow\ETL\FlowContext;
use PhpBench\Attributes\Groups;
use PhpBench\Attributes\Iterations;
use PhpBench\Attributes\Revs;

#[Iterations(5)]
#[Iterations(3)]
#[Groups(['extractor'])]
final class XmlExtractorBench
{
#[Revs(1000)]
#[Revs(5)]
public function bench_extract() : void
{
XML::from(__DIR__ . '/../Fixtures/simple_items.xml');
foreach (XML::from(__DIR__ . '/../Fixtures/simple_items.xml')->extract(new FlowContext(Config::default())) as $rows) {
}
}
}
24 changes: 2 additions & 22 deletions src/core/etl/src/Flow/ETL/Rows.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Flow\ETL;

use function Flow\ETL\DSL\array_to_rows;
use Flow\ETL\DSL\Entry;
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\Exception\RuntimeException;
Expand Down Expand Up @@ -40,28 +41,7 @@ public function __construct(Row ...$rows)

public static function fromArray(array $data, EntryFactory $entryFactory = new NativeEntryFactory()) : self
{
/** @var array<Row> $rows */
$rows = [];

foreach ($data as $entries) {
if (!\is_array($entries)) {
throw new InvalidArgumentException('Rows expects nested array data structure: array<array<mixed>>');
}

$row = [];

/**
* @var string $entryName
* @var mixed $entryValue
*/
foreach ($entries as $entryName => $entryValue) {
$row[] = $entryFactory->create($entryName, $entryValue);
}

$rows[] = Row::create(...$row);
}

return new self(...$rows);
return array_to_rows($data, $entryFactory);
}

public function __serialize() : array
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php declare(strict_types=1);

namespace Flow\ETL\Tests\Benchmark\EntryFactory;

use function Flow\ETL\DSL\array_to_rows;
use Faker\Factory;
use Flow\ETL\Row\Factory\NativeEntryFactory;
use PhpBench\Attributes\BeforeMethods;
use PhpBench\Attributes\Groups;
use PhpBench\Attributes\Iterations;
use PhpBench\Attributes\Revs;

#[Iterations(5)]
#[Groups(['entry_factory'])]
final class NativeEntryFactoryBench
{
private array $rowsArray = [];

public function setUp() : void
{
$faker = Factory::create();

$this->rowsArray = \array_map(
static fn (int $i) : array => [
'order_id' => $faker->uuid,
'created_at' => $faker->dateTimeThisYear->format(\DateTimeInterface::RFC3339),
'updated_at' => $faker->dateTimeThisMonth->format(\DateTimeInterface::RFC3339),
'cancelled_at' => ($i % 10) === 0 ? $faker->dateTimeThisMonth->format(\DateTimeInterface::RFC3339) : null,
'active' => !(($i % 20) === 0),
'total_price' => $faker->randomFloat(2, 0, 500),
'discount' => $faker->randomFloat(2, 0, 50),
'customer' => [
'name' => $faker->firstName,
'last_name' => $faker->lastName,
'email' => $faker->email,
],
'address' => [
'street' => $faker->streetAddress,
'city' => $faker->city,
'zip' => $faker->postcode,
'country' => $faker->country,
'location' => [
'lat' => $faker->latitude,
'lng' => $faker->longitude,
],
],
'notes' => \array_map(
static fn ($i) => $faker->sentence,
\range(1, $faker->numberBetween(1, 5))
),
],
\range(1, 10_000)
);
}

#[BeforeMethods(['setUp'])]
#[Revs(5)]
public function bench_10k_rows() : void
{
array_to_rows($this->rowsArray, new NativeEntryFactory());
}

#[BeforeMethods(['setUp'])]
#[Revs(5)]
public function bench_1k_rows() : void
{
array_to_rows(\array_slice($this->rowsArray, 0, 1_000), new NativeEntryFactory());
}

#[BeforeMethods(['setUp'])]
#[Revs(5)]
public function bench_5k_rows() : void
{
array_to_rows(\array_slice($this->rowsArray, 0, 5_000), new NativeEntryFactory());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
use Flow\ETL\Row;
use Flow\ETL\Rows;
use Flow\ETL\Transformer\EntryExpressionEvalTransformer;
use PhpBench\Attributes\Groups;
use PhpBench\Attributes\Iterations;
use PhpBench\Attributes\Revs;

#[Iterations(5)]
#[Groups(['transformer'])]
final class EntryExpressionEvalTransformerBench
{
#[Revs(1000)]
Expand Down
Loading

0 comments on commit 314b941

Please sign in to comment.