-
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.
* Benchmark * Add limit set * Bench react http client
- Loading branch information
Showing
6 changed files
with
129 additions
and
0 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
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,6 @@ | ||
{ | ||
"$schema":"./vendor/phpbench/phpbench/phpbench.schema.json", | ||
"runner.bootstrap": "vendor/autoload.php", | ||
"runner.path": "tests/Benchmark", | ||
"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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Fansipan\Peak\Tests\Benchmark; | ||
|
||
trait BenchTrait | ||
{ | ||
public function provideLimits(): \Generator | ||
{ | ||
yield '50 rqs' => ['limit' => 50]; | ||
yield '100 rqs' => ['limit' => 100]; | ||
yield '200 rqs' => ['limit' => 200]; | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Fansipan\Peak\Tests\Benchmark; | ||
|
||
use Fansipan\Peak\Tests\TestRequestTrait; | ||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Pool; | ||
use GuzzleHttp\RequestOptions; | ||
use PhpBench\Attributes\ParamProviders; | ||
|
||
final class DefaultBench | ||
{ | ||
use BenchTrait; | ||
use TestRequestTrait; | ||
|
||
#[ParamProviders(['provideLimits'])] | ||
public function benchGuzzlePool(array $params): void | ||
{ | ||
$options = [ | ||
RequestOptions::ALLOW_REDIRECTS => false, | ||
RequestOptions::HTTP_ERRORS => false, | ||
]; | ||
|
||
Pool::batch(new Client($options), $this->createPsrRequests($params['limit'])); | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Fansipan\Peak\Tests\Benchmark; | ||
|
||
use Fansipan\Peak\Client\GuzzleClient; | ||
use Fansipan\Peak\Client\SymfonyClient; | ||
use Fansipan\Peak\Concurrency\PslDeferred; | ||
use Fansipan\Peak\PoolFactory; | ||
use Fansipan\Peak\Tests\TestRequestTrait; | ||
use PhpBench\Attributes\ParamProviders; | ||
|
||
final class PslBench | ||
{ | ||
use BenchTrait; | ||
use TestRequestTrait; | ||
|
||
#[ParamProviders(['provideLimits'])] | ||
public function benchPslPoolUsingGuzzle(array $params): void | ||
{ | ||
PoolFactory::createFromClient( | ||
new GuzzleClient(new PslDeferred()) | ||
)->send($this->createPsrRequests($params['limit'])); | ||
} | ||
|
||
#[ParamProviders(['provideLimits'])] | ||
public function benchPslPoolUsingSymfony(array $params): void | ||
{ | ||
PoolFactory::createFromClient( | ||
new SymfonyClient(new PslDeferred()) | ||
)->send($this->createPsrRequests($params['limit'])); | ||
} | ||
} |
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 Fansipan\Peak\Tests\Benchmark; | ||
|
||
use Fansipan\Peak\Client\GuzzleClient; | ||
use Fansipan\Peak\Client\ReactClient; | ||
use Fansipan\Peak\Client\SymfonyClient; | ||
use Fansipan\Peak\Concurrency\ReactDeferred; | ||
use Fansipan\Peak\PoolFactory; | ||
use Fansipan\Peak\Tests\TestRequestTrait; | ||
use PhpBench\Attributes\ParamProviders; | ||
|
||
final class ReactBench | ||
{ | ||
use BenchTrait; | ||
use TestRequestTrait; | ||
|
||
#[ParamProviders(['provideLimits'])] | ||
public function benchReactPoolUsingGuzzle(array $params): void | ||
{ | ||
PoolFactory::createFromClient( | ||
new GuzzleClient(new ReactDeferred()) | ||
)->send($this->createPsrRequests($params['limit'])); | ||
} | ||
|
||
#[ParamProviders(['provideLimits'])] | ||
public function benchReactPoolUsingSymfony(array $params): void | ||
{ | ||
PoolFactory::createFromClient( | ||
new SymfonyClient(new ReactDeferred()) | ||
)->send($this->createPsrRequests($params['limit'])); | ||
} | ||
|
||
#[ParamProviders(['provideLimits'])] | ||
public function benchReactPoolUsingHttpClient(array $params): void | ||
{ | ||
PoolFactory::createFromClient(new ReactClient()) | ||
->send($this->createPsrRequests($params['limit'])); | ||
} | ||
} |