From 43736a2943dea1b992d20c2b5cdac0a71ba0fe9c Mon Sep 17 00:00:00 2001 From: rastusik Date: Sat, 22 Dec 2018 22:42:42 +0100 Subject: [PATCH 1/3] better-serializer benchmark added --- composer.json | 3 +- docker/php/Dockerfile | 5 +-- src/Bench/BetterSerializerBenchmark.php | 60 +++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 src/Bench/BetterSerializerBenchmark.php diff --git a/composer.json b/composer.json index 91d5b83..009354a 100644 --- a/composer.json +++ b/composer.json @@ -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": [ { diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile index 390adf2..59d21c5 100644 --- a/docker/php/Dockerfile +++ b/docker/php/Dockerfile @@ -1,4 +1,4 @@ -FROM php:latest +FROM php:7.2 # APT packages RUN apt-get update && apt-get install -y \ @@ -6,9 +6,6 @@ RUN apt-get update && apt-get install -y \ 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 \ diff --git a/src/Bench/BetterSerializerBenchmark.php b/src/Bench/BetterSerializerBenchmark.php new file mode 100644 index 0000000..45f2307 --- /dev/null +++ b/src/Bench/BetterSerializerBenchmark.php @@ -0,0 +1,60 @@ + + */ +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; + } +} From e7956145bb0597d7ea646d733bd381dec3961c9e Mon Sep 17 00:00:00 2001 From: rastusik Date: Sat, 22 Dec 2018 22:50:30 +0100 Subject: [PATCH 2/3] better-serializer benchmark added - fixed namespace --- src/Bench/BetterSerializerBenchmark.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bench/BetterSerializerBenchmark.php b/src/Bench/BetterSerializerBenchmark.php index 45f2307..f2737ca 100644 --- a/src/Bench/BetterSerializerBenchmark.php +++ b/src/Bench/BetterSerializerBenchmark.php @@ -1,6 +1,6 @@ + * @author Rastusik */ class BetterSerializerBenchmark extends AbstractBench { From 771f8395b9c29f3518e4b4d1cafafd094fd01d13 Mon Sep 17 00:00:00 2001 From: rastusik Date: Sat, 22 Dec 2018 23:00:46 +0100 Subject: [PATCH 3/3] readme updated with better serializer (first because of alphabetis ordering) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e8cf010..a5c3a37 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ $ docker-compose run --rm php ./vendor/bin/phpbench info Available implementations: +* `BetterSerializer` * `Ivory` * `JaneAutomapper` * `Jms`