diff --git a/.circleci/config.yml b/.circleci/config.yml index 8ed8d03..041b39b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,8 +5,6 @@ jobs: docker: - image: phpbenchmarks/benchmark-kit:4 working_directory: /var/www/benchmark - environment: - NGINX_PORT: 80 steps: - checkout - run: @@ -14,7 +12,7 @@ jobs: command: /var/entrypoint.sh --nginx-as-service - run: name: "benchmark:validate" - command: "/var/benchmark-kit/bin/console benchmark:validate" + command: "/var/benchmark-kit/bin/console benchmark:validate:all" workflows: version: '2.1' diff --git a/.phpbenchmarks/Configuration.php b/.phpbenchmarks/Configuration.php deleted file mode 100644 index 0a3d5c9..0000000 --- a/.phpbenchmarks/Configuration.php +++ /dev/null @@ -1,75 +0,0 @@ - 'https://github.com/phpbenchmarks/php/blob/7.4_rest-api/public/index.php', - 'randomizeLanguageDispatchEvent' => 'https://github.com/phpbenchmarks/php/blob/7.4_rest-api/public/index.php#L13', - 'randomizeLanguageEventListener' => 'https://github.com/phpbenchmarks/php/blob/7.4_rest-api/src/Translation/TranslationService.php', - 'translations' => 'https://github.com/phpbenchmarks/php/tree/7.4_rest-api/translations', - 'translate' => 'https://github.com/phpbenchmarks/php/blob/7.4_rest-api/src/ArrayEncoder/UserArrayEncoder.php#L28', - 'serialize' => 'https://github.com/phpbenchmarks/php/blob/7.4_rest-api/public/index.php#L18' - ]; - } -} diff --git a/.phpbenchmarks/config.yml b/.phpbenchmarks/config.yml new file mode 100644 index 0000000..bd03d61 --- /dev/null +++ b/.phpbenchmarks/config.yml @@ -0,0 +1,17 @@ +component: + id: 1 +benchmark: + type: 3 + relativeUrl: / +sourceCode: + entryPoint: public/index.php + urls: + entryPoint: 'https://github.com/phpbenchmarks/php/tree/7.4.2_rest-api_0/public/index.php' + randomizeLanguageDispatchEvent: 'https://github.com/phpbenchmarks/php/tree/7.4.2_rest-api_0/public/index.php#L51' + randomizeLanguageEventListener: 'https://github.com/phpbenchmarks/php/tree/7.4.2_rest-api_0/src/Translation/TranslationService.php#L11' + translations: 'https://github.com/phpbenchmarks/php/tree/7.4.2_rest-api_0/translations/phpbenchmarks.en_GB.php' + translate: 'https://github.com/phpbenchmarks/php/tree/7.4.2_rest-api_0/public/index.php#L21' + serialize: 'https://github.com/phpbenchmarks/php/tree/7.4.2_rest-api_0/public/index.php#L58' +coreDependency: + name: php + version: 7.4.2 diff --git a/.phpbenchmarks/vhost.conf b/.phpbenchmarks/nginx/vhost.conf similarity index 94% rename from .phpbenchmarks/vhost.conf rename to .phpbenchmarks/nginx/vhost.conf index 9dc7c32..d7dba5a 100644 --- a/.phpbenchmarks/vhost.conf +++ b/.phpbenchmarks/nginx/vhost.conf @@ -1,5 +1,5 @@ server { - listen 80; + listen ____PORT____; server_name ____HOST____; root ____INSTALLATION_PATH____/public; location / { diff --git a/.phpbenchmarks/composer/composer.lock.php7.4 b/.phpbenchmarks/php/7.4/composer.lock similarity index 95% rename from .phpbenchmarks/composer/composer.lock.php7.4 rename to .phpbenchmarks/php/7.4/composer.lock index 83101e6..a182fe4 100644 --- a/.phpbenchmarks/composer/composer.lock.php7.4 +++ b/.phpbenchmarks/php/7.4/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "67e054ed35b2af4a104762224ae4a621", + "content-hash": "7a6ae71c28c060a84252508251463c96", "packages": [ { "name": "phpbenchmarks/benchmark-rest-data", @@ -44,7 +44,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "7.4.0", + "php": "7.4.2", "ext-json": "*" }, "platform-dev": [] diff --git a/.phpbenchmarks/initBenchmark.sh b/.phpbenchmarks/php/7.4/initBenchmark.sh similarity index 100% rename from .phpbenchmarks/initBenchmark.sh rename to .phpbenchmarks/php/7.4/initBenchmark.sh diff --git a/.phpbenchmarks/php/7.4/php.ini b/.phpbenchmarks/php/7.4/php.ini new file mode 100644 index 0000000..e69de29 diff --git a/.phpbenchmarks/php/7.4/preload.php b/.phpbenchmarks/php/7.4/preload.php new file mode 100644 index 0000000..3e9a2d1 --- /dev/null +++ b/.phpbenchmarks/php/7.4/preload.php @@ -0,0 +1,10 @@ + $user->getId(), + 'login' => $user->getLogin(), + 'createdAt' => $user->getCreatedAt()->format('Y-m-d H:i:s'), + 'translated' => TranslationService::getTranslation('translated.1000'), + 'comments' => encodeComments($user->getComments()) + ]; +} + +/** @param Comment[] $comments */ +function encodeComments(array $comments): array +{ + $return = []; + foreach ($comments as $comment) { + $return[] = [ + 'id' => $comment->getId(), + 'message' => $comment->getMessage(), + 'translated' => TranslationService::getTranslation('translated.2000'), + 'type' => encodeType($comment->getType()) + ]; + } + + return $return; +} + +function encodeType(CommentType $type): array +{ + return [ + 'id' => $type->getId(), + 'name' => $type->getName(), + 'translated' => TranslationService::getTranslation('translated.3000') + ]; +} TranslationService::loadTranslations(); -$userEncoder = new UserArrayEncoder(); $data = []; foreach (Service::getUsers() as $user) { - $data[] = $userEncoder->encode($user); + $data[] = encodeUser($user); } echo json_encode($data); - -// require phpbenchmarks stats.php here when needed diff --git a/src/ArrayEncoder/CommentArrayEncoder.php b/src/ArrayEncoder/CommentArrayEncoder.php deleted file mode 100644 index 6927fd3..0000000 --- a/src/ArrayEncoder/CommentArrayEncoder.php +++ /dev/null @@ -1,28 +0,0 @@ -commentTypeEncoder = new CommentTypeArrayEncoder(); - } - - public function encode(Comment $comment): array - { - return [ - 'id' => $comment->getId(), - 'message' => $comment->getMessage(), - 'translated' => TranslationService::getTranslation('translated.2000'), - 'type' => $this->commentTypeEncoder->encode($comment->getType()) - ]; - } -} diff --git a/src/ArrayEncoder/CommentTypeArrayEncoder.php b/src/ArrayEncoder/CommentTypeArrayEncoder.php deleted file mode 100644 index 0185257..0000000 --- a/src/ArrayEncoder/CommentTypeArrayEncoder.php +++ /dev/null @@ -1,20 +0,0 @@ - $commentType->getId(), - 'name' => $commentType->getName(), - 'translated' => TranslationService::getTranslation('translated.3000') - ]; - } -} diff --git a/src/ArrayEncoder/UserArrayEncoder.php b/src/ArrayEncoder/UserArrayEncoder.php deleted file mode 100644 index 49f4750..0000000 --- a/src/ArrayEncoder/UserArrayEncoder.php +++ /dev/null @@ -1,35 +0,0 @@ -commentEncoder = new CommentArrayEncoder(); - } - - public function encode(User $user): array - { - return [ - 'id' => $user->getId(), - 'login' => $user->getLogin(), - 'createdAt' => $user->getCreatedAt()->format('Y-m-d H:i:s'), - 'translated' => TranslationService::getTranslation('translated.1000'), - 'comments' => array_map( - fn(Comment $comment) => $this->commentEncoder->encode($comment), - $user->getComments() - ) - ]; - } -}