Skip to content

Commit 13e2b37

Browse files
committed
Big JSON serialization benchmark for PHP 8.0.0
0 parents  commit 13e2b37

File tree

14 files changed

+293
-0
lines changed

14 files changed

+293
-0
lines changed

.circleci/config.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: '2.1'
2+
3+
jobs:
4+
ValidateBenchmark:
5+
docker:
6+
- image: phpbenchmarks/benchmark-kit:4
7+
working_directory: /var/www/benchmark
8+
steps:
9+
- checkout
10+
- run:
11+
name: entrypoint
12+
command: entrypoint --nginx-as-service
13+
- run:
14+
name: "validate:benchmark"
15+
command: "phpbenchkit validate:benchmark -vvv"
16+
17+
workflows:
18+
version: '2.1'
19+
BenchmarkKit:
20+
jobs:
21+
- ValidateBenchmark

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor
2+
/composer.lock

.phpbenchmarks/config.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
component:
2+
slug: php
3+
benchmark:
4+
type: json-serialization-big-overload
5+
relativeUrl: /
6+
sourceCode:
7+
entryPoint: public/index.php
8+
urls:
9+
jsonSerialization: 'https://github.com/phpbenchmarks/php/tree/8.0.0_json-serialization-big-overload_0/public/index.php#L15'
10+
integerSerialization: 'https://github.com/phpbenchmarks/php/tree/8.0.0_json-serialization-big-overload_0/public/index.php#L15'
11+
floatSerialization: 'https://github.com/phpbenchmarks/php/tree/8.0.0_json-serialization-big-overload_0/public/index.php#L15'
12+
stringSerialization: 'https://github.com/phpbenchmarks/php/tree/8.0.0_json-serialization-big-overload_0/public/index.php#L15'
13+
booleanSerialization: 'https://github.com/phpbenchmarks/php/tree/8.0.0_json-serialization-big-overload_0/public/index.php#L15'
14+
nullSerialization: 'https://github.com/phpbenchmarks/php/tree/8.0.0_json-serialization-big-overload_0/public/index.php#L15'
15+
arraySerialization: 'https://github.com/phpbenchmarks/php/tree/8.0.0_json-serialization-big-overload_0/public/index.php#L15'
16+
objectSerialization: 'https://github.com/phpbenchmarks/php/tree/8.0.0_json-serialization-big-overload_0/public/index.php#L15'
17+
coreDependency:
18+
name: php
19+
version: 8.0.0

.phpbenchmarks/nginx/vhost.conf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
server {
2+
listen ____PORT____;
3+
server_name ____HOST____;
4+
root ____INSTALLATION_PATH____/____ENTRY_POINT_FILE_PATH____;
5+
location / {
6+
try_files $uri /____ENTRY_POINT_FILE_NAME____$is_args$args;
7+
}
8+
location ~ ____ENTRY_POINT_FILE_NAME____(/|$) {
9+
fastcgi_pass unix:/run/php/____PHP_FPM_SOCK____;
10+
fastcgi_split_path_info ^(.+.php)(/.*)$;
11+
include fastcgi_params;
12+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
13+
fastcgi_param HTTPS off;
14+
}
15+
}

.phpbenchmarks/php/8.0/composer.lock

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# add commands to initialize benchmark: clear cache and logs, warm up cache etc
6+
composer install --no-dev --classmap-authoritative --ansi

.phpbenchmarks/php/8.0/php.ini

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; ----------------------------------------------------------------------------------------------------------------------
2+
; This file will be added to PHP ini files loaded before benchmarking.
3+
; Configure what you need here.
4+
;
5+
; /!\ Do NOT configure opcache.enable: it will be configured automatically.
6+
; /!\ Do NOT configure opcache.preload and opcache.preload_user: it will be configured automatically. /!\
7+
; ----------------------------------------------------------------------------------------------------------------------
8+
9+
; Examples of configuration you could change for your needs.
10+
11+
; The maximum number of keys (scripts) in the OPcache hash table.
12+
; Only numbers between 200 and 1000000 are allowed.
13+
;opcache.max_accelerated_files=10000
14+
15+
; If disabled, all PHPDoc comments are dropped from the code to reduce the
16+
; size of the optimized code.
17+
;opcache.save_comments=1
18+
19+
; A bitmask, where each bit enables or disables the appropriate OPcache
20+
; passes
21+
;opcache.optimization_level=0x7FFFBFFF
22+
23+
; Allows exclusion of large files from being cached. By default all files
24+
; are cached.
25+
;opcache.max_file_size=0
26+
27+
; Enables or disables opcode caching in shared memory.
28+
;opcache.file_cache_only=0
29+
30+
; The OPcache shared memory storage size.
31+
;opcache.memory_consumption=128

.phpbenchmarks/php/8.0/preload.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
$sourceCodePath = __DIR__ . '/../../../';
4+
$files = [
5+
"$sourceCodePath/public/index.php",
6+
"$sourceCodePath/src/ObjectToSerialize/JsonSerializableToSerialize.php",
7+
"$sourceCodePath/src/ObjectToSerializeFactory/JsonSerializableFactory.php",
8+
"$sourceCodePath/vendor/autoload.php",
9+
"$sourceCodePath/vendor/composer/ClassLoader.php",
10+
"$sourceCodePath/vendor/phpbenchmarks/benchmark-json-serialization-big-overload/src/BenchmarkService.php",
11+
"$sourceCodePath/vendor/phpbenchmarks/benchmark-json-serialization-big-overload/src/ObjectToSerialize/ObjectToSerialize.php",
12+
"$sourceCodePath/vendor/phpbenchmarks/benchmark-json-serialization-big-overload/src/ObjectToSerialize/ObjectToSerializeInterface.php",
13+
"$sourceCodePath/vendor/phpbenchmarks/benchmark-json-serialization-big-overload/src/ObjectToSerializeFactory/ObjectToSerializeFactoryInterface.php",
14+
];
15+
16+
foreach ($files as $file) {
17+
if (is_readable($file) === false) {
18+
throw new \Exception('File "' . $file . '" is not readable.');
19+
}
20+
21+
opcache_compile_file($file);
22+
}

.phpbenchmarks/php/8.0/responseBody/responseBody.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<p align="center">
2+
<img src="http://www.phpbenchmarks.com/images/logo_github.png">
3+
<br>
4+
<a href="http://www.phpbenchmarks.com" target="_blank">www.phpbenchmarks.com</a>
5+
</p>
6+
7+
## What is www.phpbenchmarks.com?
8+
9+
You will find a lot of benchmarks for PHP and PHP libraries on [phpbenchmarks.com](http://www.phpbenchmarks.com).
10+
11+
Benchmarks results are available from PHP 5.6 to latest version.
12+
13+
Our benchmarking protocol is available on [benchmarking protocol page](http://www.phpbenchmarks.com/en/documentation/benchmarking-protocol).
14+
15+
## What is this repository?
16+
17+
It contains PHP benchmark code.
18+
19+
Switch branch to select version and benchmark you want to see.
20+
21+
## Benchmarks
22+
23+
You can find PHP 8.0 benchmarks results on
24+
[benchmarks results page](http://www.phpbenchmarks.com/en/benchmark/php/8.0).
25+
26+
See all PHP benchmarked versions on [select version page](http://www.phpbenchmarks.com/en/benchmark/php/version).
27+
28+
## Community
29+
30+
Go to [community page](http://www.phpbenchmarks.com/en/community) to see the Hall of fame, or download the benchmark kit to add your code!
31+
32+
## How version works?
33+
34+
We do not follow semantic version for this repository.
35+
36+
Here is an explanation about our versioning system:
37+
38+
`X.Y.Z_benchmark-slug_W`
39+
40+
* `X`: PHP major version.
41+
* `Y`: PHP minor version.
42+
* `Z`: PHP patch version.
43+
* `benchmark-slug`: slug of the benchmark, list available on [documentation page](http://www.phpbenchmarks.com/en/documentation).
44+
* `W`: benchmark version

composer.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "phpbenchmarks/php",
3+
"license": "proprietary",
4+
"type": "project",
5+
"require": {
6+
"php": "8.0.0",
7+
"ext-json": "*",
8+
"phpbenchmarks/benchmark-json-serialization-big-overload": "1.0.0"
9+
},
10+
"autoload": {
11+
"psr-4": {
12+
"App\\": "src/"
13+
}
14+
}
15+
}

public/index.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use App\ObjectToSerializeFactory\JsonSerializableFactory;
6+
use PhpBenchmarks\BenchmarkJsonSerializationBigOverload\BenchmarkService;
7+
8+
require __DIR__ . '/../vendor/autoload.php';
9+
10+
$benchmarkService = new BenchmarkService(new JsonSerializableFactory());
11+
12+
if ($benchmarkService->isWriteToResponseBody()) {
13+
echo json_encode($benchmarkService->getDataToSerialize());
14+
} else {
15+
json_encode($benchmarkService->getDataToSerialize());
16+
}
17+
18+
// require phpbenchmarks stats.php here when needed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\ObjectToSerialize;
6+
7+
use PhpBenchmarks\BenchmarkJsonSerializationBigOverload\ObjectToSerialize\ObjectToSerialize;
8+
9+
class JsonSerializableToSerialize extends ObjectToSerialize implements \JsonSerializable
10+
{
11+
/** @return array */
12+
public function jsonSerialize()
13+
{
14+
return [
15+
'property1' => $this->getProperty1(),
16+
'property2' => $this->getProperty2(),
17+
'property3' => $this->getProperty3(),
18+
'property4' => $this->getProperty4(),
19+
'property5' => $this->getProperty5(),
20+
'property6' => $this->getProperty6(),
21+
'property7' => $this->getProperty7(),
22+
'property8' => $this->getProperty8(),
23+
'property9' => $this->getProperty9(),
24+
'property10' => $this->getProperty10()
25+
];
26+
}
27+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\ObjectToSerializeFactory;
6+
7+
use App\ObjectToSerialize\JsonSerializableToSerialize;
8+
use PhpBenchmarks\BenchmarkJsonSerializationBigOverload\{
9+
ObjectToSerialize\ObjectToSerializeInterface,
10+
ObjectToSerializeFactory\ObjectToSerializeFactoryInterface
11+
};
12+
13+
class JsonSerializableFactory implements ObjectToSerializeFactoryInterface
14+
{
15+
/** @return ObjectToSerializeInterface */
16+
public function create()
17+
{
18+
return new JsonSerializableToSerialize();
19+
}
20+
}

0 commit comments

Comments
 (0)