Skip to content

Commit b2c4e35

Browse files
committed
Small JSON serialization benchmark for PHP 7.4.0
0 parents  commit b2c4e35

File tree

12 files changed

+300
-0
lines changed

12 files changed

+300
-0
lines changed

.circleci/config.yml

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

.gitignore

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

.phpbenchmarks/Configuration.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpBenchmarks\BenchmarkConfiguration;
6+
7+
class Configuration
8+
{
9+
public static function getComponentType(): int
10+
{
11+
return 1;
12+
}
13+
14+
public static function getComponentName(): string
15+
{
16+
return 'PHP';
17+
}
18+
19+
public static function getComponentSlug(): string
20+
{
21+
return 'php';
22+
}
23+
24+
public static function isCompatibleWithPhp(int $major, int $minor): bool
25+
{
26+
return
27+
($major === 7 && $minor === 4);
28+
}
29+
30+
public static function getEntryPointFileName(): string
31+
{
32+
return 'public/index.php';
33+
}
34+
35+
public static function getBenchmarkUrl(): string
36+
{
37+
return '/';
38+
}
39+
40+
public static function getCoreDependencyName(): string
41+
{
42+
return 'php';
43+
}
44+
45+
public static function getCoreDependencyMajorVersion(): int
46+
{
47+
return 7;
48+
}
49+
50+
public static function getCoreDependencyMinorVersion(): int
51+
{
52+
return 4;
53+
}
54+
55+
public static function getCoreDependencyPatchVersion(): int
56+
{
57+
return 0;
58+
}
59+
60+
public static function getBenchmarkType(): int
61+
{
62+
return 7;
63+
}
64+
65+
public static function getSourceCodeUrls(): array
66+
{
67+
return [
68+
'jsonSerialization' => 'https://github.com/phpbenchmarks/php/blob/7.4_json-serialization-small-overload/public/index.php',
69+
'integerSerialization' => 'https://github.com/phpbenchmarks/php/blob/7.4_json-serialization-small-overload/src/ObjectToSerialize/JsonSerializableToSerialize.php',
70+
'floatSerialization' => 'https://github.com/phpbenchmarks/php/blob/7.4_json-serialization-small-overload/src/ObjectToSerialize/JsonSerializableToSerialize.php',
71+
'stringSerialization' => 'https://github.com/phpbenchmarks/php/blob/7.4_json-serialization-small-overload/src/ObjectToSerialize/JsonSerializableToSerialize.php',
72+
'booleanSerialization' => 'https://github.com/phpbenchmarks/php/blob/7.4_json-serialization-small-overload/src/ObjectToSerialize/JsonSerializableToSerialize.php',
73+
'nullSerialization' => 'https://github.com/phpbenchmarks/php/blob/7.4_json-serialization-small-overload/src/ObjectToSerialize/JsonSerializableToSerialize.php',
74+
'arraySerialization' => 'https://github.com/phpbenchmarks/php/blob/7.4_json-serialization-small-overload/src/ObjectToSerialize/JsonSerializableToSerialize.php',
75+
'objectSerialization' => 'https://github.com/phpbenchmarks/php/blob/7.4_json-serialization-small-overload/src/ObjectToSerialize/JsonSerializableToSerialize.php'
76+
];
77+
}
78+
}

.phpbenchmarks/composer/composer.lock.php7.4

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.phpbenchmarks/initBenchmark.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
composer install --no-dev --classmap-authoritative --ansi

.phpbenchmarks/responseBody/responseBody.json

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

.phpbenchmarks/vhost.conf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
server {
2+
listen 80;
3+
server_name ____HOST____;
4+
root ____INSTALLATION_PATH____/public;
5+
location / {
6+
try_files $uri /index.php$is_args$args;
7+
}
8+
location ~ ^/(index).php(/|$) {
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+
}

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 lot of benchmarks for PHP frameworks, template engines and JSON serializers 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+
You can find source code links into [Configuration::getSourceCodeUrls()](.phpbenchmarks/Configuration.php).
22+
23+
## Benchmarks
24+
25+
You can find PHP 7.4 benchmarks results on
26+
[benchmarks results page](http://www.phpbenchmarks.com/en/benchmark/php/7.4).
27+
28+
See all PHP benchmarked versions on [select version page](http://www.phpbenchmarks.com/en/benchmark/php/version).
29+
30+
## Community
31+
32+
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!
33+
34+
## How version works?
35+
36+
We do not follow semantic version for this repository. Here is an explanation about our versioning system:
37+
38+
`W` PHP major version.
39+
40+
`X` PHP minor version.
41+
42+
`Y` PHP patch version.
43+
44+
`Z` Benchmark type: `1`: Hello world, `3`: REST API, `6` JSON serialization of Hello world, `7` Small JSON serialization, `8` Big JSON serialization.

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": "7.4.0",
7+
"ext-json": "*",
8+
"phpbenchmarks/benchmark-json-serialization-small-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\BenchmarkJsonSerializationSmallOverload\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\BenchmarkJsonSerializationSmallOverload\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\BenchmarkJsonSerializationSmallOverload\{
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)