Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better-serializer benchmark added #17

Merged
merged 3 commits into from
Dec 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ $ docker-compose run --rm php ./vendor/bin/phpbench info

Available implementations:

* `BetterSerializer`
* `Ivory`
* `JaneAutomapper`
* `Jms`
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"thunderer/serializard": "^0.3",
"phpbench/phpbench": "^0.14.0",
"tsantos/serializer": "dev-jms-metadata-v2",
"ocramius/package-versions": "^1.3"
"ocramius/package-versions": "^1.3",
"better-serializer/better-serializer": "^0.1"
},
"authors": [
{
Expand Down
5 changes: 1 addition & 4 deletions docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
FROM php:latest
FROM php:7.2

# APT packages
RUN apt-get update && apt-get install -y \
zlib1g-dev \
git \
&& rm -rf /var/lib/apt/lists/*

# PHP extensions
RUN docker-php-ext-install zip

# APCU extension
RUN pecl install apcu \
&& docker-php-ext-enable apcu \
Expand Down
60 changes: 60 additions & 0 deletions src/Bench/BetterSerializerBenchmark.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace PhpSerializers\Benchmarks\Bench;

use BetterSerializer\Builder;
use BetterSerializer\Common\SerializationType;
use BetterSerializer\Serializer;
use PhpSerializers\Benchmarks\AbstractBench;
use PhpSerializers\Benchmarks\Model\Forum;

/**
* @author Rastusik
*/
class BetterSerializerBenchmark extends AbstractBench
{

/**
* @var Serializer
*/
private $serializer;

/**
* {@inheritdoc}
*/
public function initSerializer(): void
{
$builder = new Builder();

if (extension_loaded('apcu') && ini_get('apc.enabled')) {
$builder->enableApcuCache();
} else {
$builder->enableFilesystemCache(dirname(__DIR__, 1) . '/cache/better-serializer');
}

$this->serializer = $builder->createSerializer();
}

/**
* {@inheritdoc}
*/
public function serialize(Forum $data): void
{
$this->serializer->serialize(
$data,
SerializationType::JSON()
);
}

public function getPackageName(): string
{
return 'better-serializer/better-serializer';
}

public function getNote(): string
{
return <<<'NOTE'
Serializer for PHP 7.2+ supporting JSON
NOTE;
}
}