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 13, 2023
1 parent b1d5ad7 commit 8ebce7a
Show file tree
Hide file tree
Showing 6 changed files with 1,602 additions and 0 deletions.
3 changes: 3 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=default"
],
"test:mutation": [
"tools/infection/vendor/bin/infection -j2"
],
Expand Down
6 changes: 6 additions & 0 deletions phpbench.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php declare(strict_types=1);

namespace Flow\ETL\Tests\Benchmark\Row\Reference\Expression;

use function Flow\ETL\DSL\lit;
use function Flow\ETL\DSL\ref;
use Flow\ETL\DSL\From;
use Flow\ETL\DSL\To;
use Flow\ETL\Flow;
use Flow\ETL\Memory\ArrayMemory;
use PhpBench\Attributes\Iterations;
use PhpBench\Attributes\Revs;

final class AddJsonBench
{
#[Revs(100)]
#[Iterations(5)]
public function benchAddingJson() : void
{
(new Flow())
->read(
From::array([['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]]])
)
->withEntry('array', ref('array')->arrayMerge(lit(['d' => 4])))
->write(To::memory(new ArrayMemory()))
->run();
}

#[Revs(100)]
#[Iterations(5)]
public function benchAddingJsonStringIntoExistingReference() : void
{
(new Flow())
->read(
From::array([['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]]])
)
->withEntry('json', lit('{"d": 4}'))
->withEntry('array', ref('array')->arrayMerge(ref('json')->jsonDecode()))
->drop('json')
->write(To::memory(new ArrayMemory()))
->run();
}
}
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 8ebce7a

Please sign in to comment.