Skip to content

Commit 0e852b4

Browse files
committed
chore(Bench): Cleanup
1 parent aef4692 commit 0e852b4

File tree

11 files changed

+92
-168
lines changed

11 files changed

+92
-168
lines changed

src/Application/Application.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Testo\Application\Value\RunResult;
1717
use Testo\Common\Container;
1818
use Testo\Core\Value\Status;
19-
use Testo\Event\Framework\FrameworkStarting;
2019
use Testo\Event\Framework\SessionFinished;
2120
use Testo\Event\Framework\SessionStarting;
2221
use Testo\Event\Framework\WorkerFinished;
@@ -99,7 +98,7 @@ public function run(?Filter $filter = null): RunResult
9998
$suiteProvider = $this->container->get(SuiteProvider::class);
10099
$suiteRunner = $this->container->get(SuiteRunner::class);
101100
$status = Status::Passed;
102-
$duration = microtime(true);
101+
$duration = \microtime(true);
103102

104103
# Iterate and run Test Suites
105104
$suiteResults = [];
@@ -108,7 +107,7 @@ public function run(?Filter $filter = null): RunResult
108107
$suiteResult->status->isFailure() and $status = Status::Failed;
109108
}
110109

111-
$duration = microtime(true) - $duration;
110+
$duration = \microtime(true) - $duration;
112111
$result = new RunResult($suiteResults, status: $status, duration: $duration);
113112

114113
$dispatcher->dispatch(new WorkerFinished());

src/Bench/Internal/BenchInvoker.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
use Testo\Bench\Exception\BenchWithAttributeMissingException;
1414
use Testo\Core\Context\TestInfo;
1515

16+
/**
17+
* @internal
18+
*/
1619
final class BenchInvoker
1720
{
1821
public function __invoke(TestInfo $info): mixed
@@ -70,7 +73,7 @@ functions: $functions,
7073
$summaryTable = \Testo\Bench\Internal\Renderer::table($result);
7174
$itersTable = \Testo\Bench\Internal\Renderer::rounds($result);
7275
echo <<<EOT
73-
Summary:
76+
Results for {$info->name}:
7477
$summaryTable
7578
7679
Iterations:

src/Bench/Internal/Calculator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use Testo\Bench\Dto\Snap;
1010
use Testo\Inline\TestInline;
1111

12+
/**
13+
* @internal
14+
*/
1215
final class Calculator
1316
{
1417
/**

src/Bench/Internal/Explanator.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
use Testo\Bench\Dto\Report;
1111
use Testo\Bench\Dto\ValueRel;
1212

13+
/**
14+
* @internal
15+
*/
1316
final class Explanator
1417
{
1518
/**
@@ -50,7 +53,7 @@ public static function prepareLines(array $cases, array $results): array
5053
),
5154
frstdev: $result->frstdev,
5255
rejected: $result->rejected,
53-
reports: self::comment($result, $cases[$k]),
56+
reports: self::explain($result, $cases[$k]),
5457
);
5558
}
5659

@@ -59,14 +62,12 @@ public static function prepareLines(array $cases, array $results): array
5962
return $lines;
6063
}
6164

62-
6365
/**
6466
* Generates a comment for a given case result, potentially based on the presence of outliers or other factors.
6567
*
66-
* @param CaseResult $result The result for which to generate the comment.
6768
* @return list<Report> A list of reports (comments, warnings, errors) related to the benchmark execution.
6869
*/
69-
private static function comment(CaseResult $caseResult, CaseSet $caseSet): array
70+
private static function explain(CaseResult $caseResult, CaseSet $caseSet): array
7071
{
7172
$result = [];
7273

@@ -83,7 +84,7 @@ private static function comment(CaseResult $caseResult, CaseSet $caseSet): array
8384
? \abs($mean - $caseResult->med) / $caseResult->med * 100
8485
: 0.0;
8586

86-
// RStDev × iter time
87+
// RStDev* × iter time
8788
match (true) {
8889
$frstdev > 20.0 && $iterTime < 10.0 => $result[] = new Report\UnreliableLowIterTime($frstdev, $iterTime),
8990
$frstdev > 20.0 => $result[] = new Report\VeryHighVariance($frstdev),
@@ -99,7 +100,7 @@ private static function comment(CaseResult $caseResult, CaseSet $caseSet): array
99100
default => null,
100101
};
101102

102-
// |Mean − Median| / Median
103+
// |Mean* − Median| / Median
103104
match (true) {
104105
$skew > 10.0 => $result[] = new Report\HeavilySkewed($skew),
105106
$skew >= 5.0 => $result[] = new Report\SkewedDistribution($skew),
@@ -123,5 +124,4 @@ private static function comment(CaseResult $caseResult, CaseSet $caseSet): array
123124

124125
return $result;
125126
}
126-
127127
}

src/Bench/Internal/Renderer.php

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -112,44 +112,6 @@ public static function table(BenchResult $result): string
112112
return \implode("\n", $lines) . self::recommendations($result);
113113
}
114114

115-
private static function recommendations(BenchResult $result): string
116-
{
117-
$dangers = [];
118-
$warnings = [];
119-
$notices = [];
120-
121-
foreach ($result->lines as $line) {
122-
foreach ($line->reports as $report) {
123-
match ($report->severity) {
124-
Severity::Danger => $dangers[$report->reason] = $report->advice,
125-
Severity::Warning => $warnings[$report->reason] = $report->advice,
126-
Severity::Notice => $notices[$report->reason] = $report->advice,
127-
default => null,
128-
};
129-
}
130-
}
131-
132-
if ($dangers === [] && $warnings === [] && $notices === []) {
133-
return '';
134-
}
135-
136-
$lines = ['', 'Recommendations:'];
137-
138-
foreach ($dangers as $reason => $advice) {
139-
$lines[] = "{$reason}: {$advice}";
140-
}
141-
142-
foreach ($warnings as $reason => $advice) {
143-
$lines[] = "{$reason}: {$advice}";
144-
}
145-
146-
foreach ($notices as $reason => $advice) {
147-
$lines[] = "{$reason}: {$advice}";
148-
}
149-
150-
return \implode("\n", $lines);
151-
}
152-
153115
public static function rounds(BenchResult $result): string
154116
{
155117
if ($result->cases === []) {
@@ -190,6 +152,44 @@ public static function rounds(BenchResult $result): string
190152
return \implode("\n", $lines);
191153
}
192154

155+
private static function recommendations(BenchResult $result): string
156+
{
157+
$dangers = [];
158+
$warnings = [];
159+
$notices = [];
160+
161+
foreach ($result->lines as $line) {
162+
foreach ($line->reports as $report) {
163+
match ($report->severity) {
164+
Severity::Danger => $dangers[$report->reason] = $report->advice,
165+
Severity::Warning => $warnings[$report->reason] = $report->advice,
166+
Severity::Notice => $notices[$report->reason] = $report->advice,
167+
default => null,
168+
};
169+
}
170+
}
171+
172+
if ($dangers === [] && $warnings === [] && $notices === []) {
173+
return '';
174+
}
175+
176+
$lines = ['', 'Recommendations:'];
177+
178+
foreach ($dangers as $reason => $advice) {
179+
$lines[] = "{$reason}: {$advice}";
180+
}
181+
182+
foreach ($warnings as $reason => $advice) {
183+
$lines[] = "{$reason}: {$advice}";
184+
}
185+
186+
foreach ($notices as $reason => $advice) {
187+
$lines[] = "{$reason}: {$advice}";
188+
}
189+
190+
return \implode("\n", $lines);
191+
}
192+
193193
private static function formatMemory(float $bytes): string
194194
{
195195
if ($bytes === 0.0) {

src/Bridge/Symfony/Command/Base.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,4 @@ protected function getConfigFile(InputInterface $input): ?Path
110110

111111
return null;
112112
}
113-
114113
}

src/Bridge/Symfony/TerminalRenderer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ public function configure(Container $container): void
7474
$listeners->addListener(TestSuiteFinished::class, $this->onTestSuiteFinished(...));
7575
}
7676

77+
private static function getId(TestInfo $testInfo): string
78+
{
79+
return \spl_object_hash($testInfo->testDefinition);
80+
}
81+
7782
private function onSessionStarting(SessionStarting $event): void
7883
{
7984
$this->logger->ensureHeader();
@@ -85,11 +90,6 @@ private function onSessionFinished(SessionFinished $event): void
8590
$this->logger->printSummary($event->result->duration);
8691
}
8792

88-
private static function getId(TestInfo $testInfo): string
89-
{
90-
return \spl_object_hash($testInfo->testDefinition);
91-
}
92-
9393
private function onTestPipelineFinished(TestPipelineFinished $event): void
9494
{
9595
// Check if this test was inside a DataProvider batch

src/Common/Environment.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,6 @@ final class Environment
1919

2020
private function __construct() {}
2121

22-
private static function init(): void
23-
{
24-
static $skip = false;
25-
if ($skip) {
26-
return;
27-
}
28-
29-
$skip = true;
30-
self::$phpVersion = \phpversion();
31-
self::$os = \php_uname('s') . ' ' . \php_uname('r');
32-
self::$cpu = \php_uname('m');
33-
self::$xDebugExists = \extension_loaded('xdebug');
34-
self::$xDebugVersion = self::$xDebugExists ? \phpversion('xdebug') : null;
35-
self::$opCacheEnabled = \extension_loaded('Zend OPcache') && \ini_get('opcache.enable_cli') === '1';
36-
self::$jitEnabled = self::$opCacheEnabled && ((int) \ini_get('opcache.jit_buffer_size')) > 0;
37-
}
38-
3922
public static function getPhpVersion(): string
4023
{
4124
self::init();
@@ -90,4 +73,21 @@ public static function isJitEnabled(): bool
9073
self::init();
9174
return self::$jitEnabled;
9275
}
76+
77+
private static function init(): void
78+
{
79+
static $skip = false;
80+
if ($skip) {
81+
return;
82+
}
83+
84+
$skip = true;
85+
self::$phpVersion = \phpversion();
86+
self::$os = \php_uname('s') . ' ' . \php_uname('r');
87+
self::$cpu = \php_uname('m');
88+
self::$xDebugExists = \extension_loaded('xdebug');
89+
self::$xDebugVersion = self::$xDebugExists ? \phpversion('xdebug') : null;
90+
self::$opCacheEnabled = \extension_loaded('Zend OPcache') && \ini_get('opcache.enable_cli') === '1';
91+
self::$jitEnabled = self::$opCacheEnabled && ((int) \ini_get('opcache.jit_buffer_size')) > 0;
92+
}
9393
}

src/Teamcity/Teamcity/TeamcityLogger.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,6 @@ public function logEnvironment(): void
7171
$this->publish(Formatter::blockClosed('Environment'));
7272
}
7373

74-
private static function key(string $name): string
75-
{
76-
return "\033[36;1m{$name}:\033[0m ";
77-
}
78-
79-
private static function dim(string $text): string
80-
{
81-
return "\033[2m{$text}\033[0m";
82-
}
83-
8474
/**
8575
* Publishes test suite started message using SuiteInfo.
8676
*/
@@ -251,6 +241,16 @@ public function handleSingleTestResult(TestResult $result, ?int $duration = null
251241
};
252242
}
253243

244+
private static function key(string $name): string
245+
{
246+
return "\033[36;1m{$name}:\033[0m ";
247+
}
248+
249+
private static function dim(string $text): string
250+
{
251+
return "\033[2m{$text}\033[0m";
252+
}
253+
254254
/**
255255
* Handles passed test status.
256256
*

src/Teamcity/TeamcityRenderer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ public function configure(Container $container): void
6161
$listeners->addListener(TestSuiteFinished::class, $this->onTestSuiteFinished(...));
6262
}
6363

64-
private function onSessionStarting(SessionStarting $event): void
64+
private static function getId(TestInfo $testInfo): string
6565
{
66-
$this->logger->logEnvironment();
66+
return \spl_object_hash($testInfo->testDefinition);
6767
}
6868

69-
private static function getId(TestInfo $testInfo): string
69+
private function onSessionStarting(SessionStarting $event): void
7070
{
71-
return \spl_object_hash($testInfo->testDefinition);
71+
$this->logger->logEnvironment();
7272
}
7373

7474
private function onTestPipelineFinished(TestPipelineFinished $event): void

0 commit comments

Comments
 (0)