-
-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1365 from scyzoryck/add-phpbench
Add performnace benchmarks
- Loading branch information
Showing
8 changed files
with
156 additions
and
73 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,34 @@ | ||
name: Benchmarks | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
phpbench: | ||
name: "PHPBench" | ||
runs-on: "ubuntu-20.04" | ||
|
||
strategy: | ||
matrix: | ||
php-version: | ||
- "7.2" | ||
- "8.0" | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-version }} | ||
|
||
- name: "Install dependencies with Composer" | ||
uses: "ramsey/composer-install@v1" | ||
|
||
- name: Run tests | ||
run: | | ||
vendor/bin/phpbench run tests/Benchmark/ --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 @@ | ||
{ | ||
"runner.bootstrap": "tests/bootstrap.php", | ||
"runner.iterations": 3, | ||
"runner.revs": 1 | ||
} |
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,75 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JMS\Serializer\Tests\Benchmark; | ||
|
||
use JMS\Serializer\SerializationContext; | ||
use JMS\Serializer\Serializer; | ||
use JMS\Serializer\SerializerBuilder; | ||
use JMS\Serializer\Tests\Fixtures\Author; | ||
use JMS\Serializer\Tests\Fixtures\BlogPost; | ||
use JMS\Serializer\Tests\Fixtures\Comment; | ||
use JMS\Serializer\Tests\Fixtures\Publisher; | ||
|
||
abstract class AbstractSerializationBench | ||
{ | ||
/** | ||
* @var Serializer | ||
*/ | ||
private $serializer; | ||
|
||
/** | ||
* @var array|BlogPost[] | ||
*/ | ||
private $collection; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $format; | ||
|
||
public function __construct() | ||
{ | ||
$this->serializer = SerializerBuilder::create()->build(); | ||
$this->collection = $this->createCollection(); | ||
$this->format = $this->getFormat(); | ||
} | ||
|
||
public function benchSerialization(): void | ||
{ | ||
$this->serializer->serialize($this->collection, $this->format, $this->createContext()); | ||
} | ||
|
||
abstract protected function getFormat(): string; | ||
|
||
protected function createContext(): SerializationContext | ||
{ | ||
return new SerializationContext(); | ||
} | ||
|
||
private function createCollection() | ||
{ | ||
$collection = []; | ||
for ($i = 0; $i < 200; $i++) { | ||
$collection[] = $this->createPost(); | ||
} | ||
|
||
return $collection; | ||
} | ||
|
||
private function createPost() | ||
{ | ||
$post = new BlogPost( | ||
'FooooooooooooooooooooooBAR', | ||
new Author('Foo'), | ||
new \DateTime(), | ||
new Publisher('bar') | ||
); | ||
for ($i = 0; $i < 100; $i++) { | ||
$post->addComment(new Comment(new Author('foo'), 'foobar')); | ||
} | ||
|
||
return $post; | ||
} | ||
} |
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 JMS\Serializer\Tests\Benchmark; | ||
|
||
use JMS\Serializer\SerializationContext; | ||
|
||
class JsonMaxDepthSerializationBench extends JsonSerializationBench | ||
{ | ||
protected function createContext(): SerializationContext | ||
{ | ||
return parent::createContext()->enableMaxDepthChecks(); | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JMS\Serializer\Tests\Benchmark; | ||
|
||
class JsonSerializationBench extends AbstractSerializationBench | ||
{ | ||
protected function getFormat(): string | ||
{ | ||
return 'json'; | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JMS\Serializer\Tests\Benchmark; | ||
|
||
class XmlSerializationBench extends AbstractSerializationBench | ||
{ | ||
protected function getFormat(): string | ||
{ | ||
return 'xml'; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.