-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6326c79
commit 0868eb4
Showing
10 changed files
with
465 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
on: [ pull_request, push ] | ||
|
||
name: "Benchmark" | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
tests: | ||
name: Benchmark | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php-version: | ||
- 8.1 | ||
- 8.2 | ||
- 8.3 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: "${{ matrix.php-version }}" | ||
|
||
- name: Install dependencies | ||
uses: php-actions/composer@v6 | ||
|
||
- name: Run benchmark | ||
run: vendor/bin/phpbench run tests/bench --report=aggregate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"$schema": "./vendor/phpbench/phpbench/phpbench.schema.json", | ||
"runner.bootstrap": "vendor/autoload.php", | ||
"runner.file_pattern": "*Bench.php" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Norvica\Pathfinder\Bench; | ||
|
||
use Norvica\Pathfinder\Pathfinder; | ||
use PhpBench\Attributes\Iterations; | ||
use PhpBench\Attributes\OutputTimeUnit; | ||
use PhpBench\Attributes\Revs; | ||
use PhpBench\Attributes\Warmup; | ||
|
||
#[Revs(100)] | ||
#[Iterations(5)] | ||
#[Warmup(2)] | ||
#[OutputTimeUnit("milliseconds", 3)] | ||
final class ColdBench | ||
{ | ||
public function benchFirstRoute(): void | ||
{ | ||
$router = new Pathfinder(); | ||
$routing = require __DIR__ . '/../routes/routes.php'; | ||
$routing($router); | ||
$router->match('GET', '/users'); | ||
} | ||
|
||
public function benchLastRoute(): void | ||
{ | ||
$router = new Pathfinder(); | ||
$routing = require __DIR__ . '/../routes/routes.php'; | ||
$routing($router); | ||
$router->match('POST', '/api/workflow/9999/stages/6666/tasks/3333/subtasks/1111/complete'); | ||
} | ||
|
||
public function bench404(): void | ||
{ | ||
$router = new Pathfinder(); | ||
$routing = require __DIR__ . '/../routes/routes.php'; | ||
$routing($router); | ||
$router->match('GET', '/api/workflow/9999/stages/6666/tasks/3333/subtasks/1111/complete!'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Norvica\Pathfinder\Bench; | ||
|
||
use Norvica\Pathfinder\Cache; | ||
use Norvica\Pathfinder\Pathfinder; | ||
use PhpBench\Attributes\Iterations; | ||
use PhpBench\Attributes\OutputTimeUnit; | ||
use PhpBench\Attributes\Revs; | ||
use PhpBench\Attributes\Warmup; | ||
|
||
#[Revs(10000)] | ||
#[Iterations(5)] | ||
#[Warmup(2)] | ||
#[OutputTimeUnit("milliseconds", 3)] | ||
final class InstantiatedBench | ||
{ | ||
private Pathfinder $pathfinder; | ||
|
||
public function __construct() | ||
{ | ||
$this->pathfinder = new Pathfinder(); | ||
$routing = require __DIR__ . '/../routes/routes.php'; | ||
$routing($this->pathfinder); | ||
|
||
$tree = $this->pathfinder->tree(); | ||
(new Cache(__DIR__ . '/../../var/pathfinder_cache'))->write($tree); | ||
|
||
$tree = (new Cache(__DIR__ . '/../../var/pathfinder_cache'))->read(); | ||
$this->pathfinder = new Pathfinder($tree); | ||
} | ||
|
||
public function benchFirstRoute(): void | ||
{ | ||
$this->pathfinder->match('GET', '/users'); | ||
} | ||
|
||
public function benchLastRoute(): void | ||
{ | ||
$this->pathfinder->match('POST', '/api/workflow/9999/stages/6666/tasks/3333/subtasks/1111/complete'); | ||
} | ||
|
||
public function bench404(): void | ||
{ | ||
$this->pathfinder->match('GET', '/api/workflow/9999/stages/6666/tasks/3333/subtasks/1111/complete!'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Norvica\Pathfinder\Bench; | ||
|
||
use Norvica\Pathfinder\Cache; | ||
use Norvica\Pathfinder\Pathfinder; | ||
use PhpBench\Attributes\Iterations; | ||
use PhpBench\Attributes\OutputTimeUnit; | ||
use PhpBench\Attributes\Revs; | ||
use PhpBench\Attributes\Warmup; | ||
|
||
#[Revs(100)] | ||
#[Iterations(5)] | ||
#[Warmup(2)] | ||
#[OutputTimeUnit("milliseconds", 3)] | ||
final class WarmBench | ||
{ | ||
public function __construct() | ||
{ | ||
$router = new Pathfinder(); | ||
$routing = require __DIR__ . '/../routes/routes.php'; | ||
$routing($router); | ||
|
||
$tree = $router->tree(); | ||
(new Cache(__DIR__ . '/../../var/pathfinder_cache'))->write($tree); | ||
} | ||
|
||
public function benchFirstRoute(): void | ||
{ | ||
$tree = (new Cache(__DIR__ . '/../../var/pathfinder_cache'))->read(); | ||
$router = new Pathfinder($tree); | ||
|
||
$router->match('GET', '/users'); | ||
} | ||
|
||
public function benchLastRoute(): void | ||
{ | ||
$tree = (new Cache(__DIR__ . '/../../var/pathfinder_cache'))->read(); | ||
$router = new Pathfinder($tree); | ||
|
||
$router->match('POST', '/api/workflow/9999/stages/6666/tasks/3333/subtasks/1111/complete'); | ||
} | ||
|
||
public function bench404(): void | ||
{ | ||
$tree = (new Cache(__DIR__ . '/../../var/pathfinder_cache'))->read(); | ||
$router = new Pathfinder($tree); | ||
|
||
$router->match('GET', '/api/workflow/9999/stages/6666/tasks/3333/subtasks/1111/complete!'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Norvica\Pathfinder\Cache; | ||
use Norvica\Pathfinder\Pathfinder; | ||
|
||
require __DIR__ . '/../src/Cache.php'; | ||
require __DIR__ . '/../src/Pathfinder.php'; | ||
|
||
$pathfinder = setup(); | ||
for($i = 0; $i < 10000; ++$i) { | ||
$pathfinder->match('POST', '/api/workflow/9999/stages/6666/tasks/3333/subtasks/1111/complete'); | ||
} | ||
|
||
function setup(): Pathfinder | ||
{ | ||
$pathfinder = new Pathfinder(); | ||
$routing = require __DIR__ . '/routes/routes.php'; | ||
$routing($pathfinder); | ||
|
||
$tree = $pathfinder->tree(); | ||
(new Cache(__DIR__ . '/../var/pathfinder_cache'))->write($tree); | ||
|
||
$tree = (new Cache(__DIR__ . '/../var/pathfinder_cache'))->read(); | ||
return new Pathfinder($tree); | ||
} |
Oops, something went wrong.