Skip to content

Commit daf2f3c

Browse files
committed
improve bench
1 parent 89004be commit daf2f3c

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,5 @@ jobs:
3838
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
3939
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
4040
41-
- name: Execute tests with mutation
42-
if: ${{ matrix.os == 'ubuntu-latest' && matrix.php == '8.5' }}
43-
run: vendor/bin/pest --colors=always --mutate --parallel --min=50
44-
4541
- name: Execute tests
46-
if: ${{ matrix.os != 'ubuntu-latest' || matrix.php != '8.5' }}
47-
run: vendor/bin/pest --colors=always
42+
run: vendor/bin/pest --colors=always --parallel

benchmarks/JsonRepairerBench.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
/**
1313
* @Revs(100)
14-
* @Iterations(20)
14+
* @Iterations(10)
1515
* @Warmup(2)
1616
*/
1717
class JsonRepairerBench
@@ -41,7 +41,15 @@ public function benchRepairValidJson(array $params): void
4141
}
4242

4343
/**
44+
* Benchmarks large JSON repair.
45+
*
46+
* Note: This benchmark uses fewer revs/iterations since it processes
47+
* 1000 items and takes ~44ms per run. Use --filter=benchRepairLargeJson
48+
* to run it separately.
49+
*
4450
* @ParamProviders({"provideLargeJson"})
51+
* @Revs(10)
52+
* @Iterations(5)
4553
*/
4654
public function benchRepairLargeJson(array $params): void
4755
{
@@ -81,6 +89,16 @@ public function benchRepairStreamingJson(array $params): void
8189
json_repair($params['json']);
8290
}
8391

92+
/**
93+
* Baseline: compare repair overhead against native json_decode on valid JSON.
94+
*
95+
* @ParamProviders({"provideValidJson"})
96+
*/
97+
public function benchNativeJsonDecodeBaseline(array $params): void
98+
{
99+
json_decode($params['json']);
100+
}
101+
84102
/**
85103
* @return array<string, array<string, string>>
86104
*/
@@ -141,7 +159,7 @@ public function provideLargeJson(): array
141159
$brokenJson = rtrim($brokenJson, '}') . ',}';
142160

143161
return [
144-
'large_array' => ['json' => $brokenJson],
162+
'large_array_broken' => ['json' => $brokenJson],
145163
];
146164
}
147165

phpbench.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22
"$schema": "https://raw.githubusercontent.com/phpbench/phpbench/master/lib/phpbench.schema.json",
33
"runner.bootstrap": "vendor/autoload.php",
44
"runner.path": "benchmarks",
5-
"runner.iterations": 20,
5+
"runner.iterations": 10,
66
"runner.revs": 100,
77
"runner.warmup": 2,
8-
"runner.time_unit": "microseconds"
8+
"runner.time_unit": "microseconds",
9+
"report.generators": {
10+
"compare": {
11+
"generator": "table",
12+
"cols": ["benchmark", "subject", "set", "revs", "its", "mem_peak", "mode", "rstdev"]
13+
}
14+
}
915
}

0 commit comments

Comments
 (0)