Skip to content

Commit fa6cd83

Browse files
committed
Updated blancks/fast-jsonpatch-php to v2
1 parent c4547b6 commit fa6cd83

File tree

5 files changed

+31
-23
lines changed

5 files changed

+31
-23
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The compliance test strictly checks if the output json of each library is consis
4444

4545
| Library / Status | Version |
4646
|--------------------------------------------------------------------------------------------------------------------------------------------------------------|------------|
47-
| <div align="right">![blancks/fast-jsonpatch-php](https://github.com/blancks/php-jsonpatch-benchmarks/workflows/blancks/fast-jsonpatch-php/badge.svg)</div> | v1.2.3 |
47+
| <div align="right">![blancks/fast-jsonpatch-php](https://github.com/blancks/php-jsonpatch-benchmarks/workflows/blancks/fast-jsonpatch-php/badge.svg)</div> | v2.0 |
4848
| <div align="right">![remorhaz/php-json-patch](https://github.com/blancks/php-jsonpatch-benchmarks/workflows/remorhaz/php-json-patch/badge.svg)</div> | v0.6.1 |
4949
| <div align="right">![mikemccabe/json-patch-php](https://github.com/blancks/php-jsonpatch-benchmarks/workflows/mikemccabe/json-patch-php/badge.svg)</div> | dev-master |
5050
| <div align="right">![php-jsonpatch/php-jsonpatch](https://github.com/blancks/php-jsonpatch-benchmarks/workflows/php-jsonpatch/php-jsonpatch/badge.svg)</div> | v4.1.0 |
@@ -61,15 +61,18 @@ The compliance test strictly checks if the output json of each library is consis
6161
The following table shows the average time each library took to apply a patch with 1000 operations to a target document as summary of the performance.
6262
The actual benchmark data is available [here](https://docs.google.com/spreadsheets/d/1ZTDWh1k-zzhYHqZB3JMD2WRV0bPRIWUMRbLiMJhMLHk/edit?usp=sharing).
6363

64-
| Library | Microseconds |
64+
| Library (fully RFC compliant only) | Microseconds |
65+
|------------------------------------|--------------|
66+
| blancks/fast-jsonpatch-php | 4511 |
67+
| remorhaz/php-json-patch | 870711 |
68+
69+
| Library (others) | Microseconds |
6570
|-----------------------------|--------------|
66-
| blancks/fast-jsonpatch-php | 2903 |
6771
| mikemccabe/json-patch-php | 3355 |
6872
| swaggest/json-diff | 3638 |
6973
| gamringer/php-json-patch | 7276 |
7074
| xp-forge/json-patch | 8534 |
7175
| php-jsonpatch/php-jsonpatch | 10970 |
72-
| remorhaz/php-json-patch | 870711 |
7376

7477
> These results are indicative and may vary depending on the specific use case and system environment.
7578

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
],
1818
"require": {
19-
"blancks/fast-jsonpatch-php": "^1.2",
19+
"blancks/fast-jsonpatch-php": "dev-dev-v2",
2020
"mikemccabe/json-patch-php": "dev-master",
2121
"php-jsonpatch/php-jsonpatch": "^4.1",
2222
"xp-forge/json-patch": "^2.1",

composer.lock

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

src/lib/blancks_fast-jsonpatch.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
function applyJsonPatch(string &$json, string $patch): float
66
{
7+
static $FastJsonPatch = null;
78
$jsonDecoded = json_decode($json);
8-
$patchDecoded = json_decode($patch);
9+
$FastJsonPatch ??= new \blancks\JsonPatch\FastJsonPatch($jsonDecoded);
910

1011
$microtime = microtime(true);
11-
\blancks\JsonPatch\FastJsonPatch::applyByReference($jsonDecoded, $patchDecoded);
12+
$FastJsonPatch->apply($patch);
1213
$output = microtime(true) - $microtime;
1314

1415
$json = json_encode($jsonDecoded);

tests/Blancks_fast_jsonpatchTest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
11
<?php declare(strict_types=1);
22

33
namespace blancks\JsonPatchBenchmarkTests;
4+
use blancks\JsonPatch\exceptions\FastJsonPatchException;
5+
use blancks\JsonPatch\FastJsonPatch;
46
use PHPUnit\Framework\Attributes\DataProvider;
57

68
class Blancks_fast_jsonpatchTest extends JsonPatchCompliance
79
{
810
#[DataProvider('validOperationsProvider')]
911
public function testJsonPatchCompliance(string $json, string $patch, string $expected): void
1012
{
13+
$document = json_decode($json);
14+
(new FastJsonPatch($document))->apply($patch);
15+
1116
$this->assertSame(
12-
json_encode(json_decode($expected, false, 512, JSON_THROW_ON_ERROR)),
13-
\blancks\JsonPatch\FastJsonPatch::apply($json, $patch)
17+
$this->normalizeJson($expected),
18+
$this->normalizeJson(json_encode($document))
1419
);
1520
}
1621

1722
#[DataProvider('atomicOperationsProvider')]
1823
public function testAtomicOperations(string $json, string $patch, string $expected): void
1924
{
20-
$document = json_decode($json);
25+
$FastJsonPatch = FastJsonPatch::fromJson($json);
2126

22-
try {
23-
\blancks\JsonPatch\FastJsonPatch::applyByReference($document, json_decode($patch));
24-
} catch (\Throwable) {
25-
// expecting some error
26-
}
27+
$this->expectException(FastJsonPatchException::class);
28+
$FastJsonPatch->apply($patch);
2729

2830
$this->assertSame(
2931
$this->normalizeJson($expected),
30-
$this->normalizeJson(json_encode($document))
32+
$this->normalizeJson($this->jsonEncode($FastJsonPatch->getDocument()))
3133
);
3234
}
3335
}

0 commit comments

Comments
 (0)