$benchmarkResults * @param LoadTestResult|null $loadTestResult * @return string HTML content */ public function generateHtmlReport( array $benchmarkResults, ?LoadTestResult $loadTestResult = null ): string { $html = << Performance Test Report

Performance Test Report

Generated: {$this->getCurrentTimestamp()}

Total Benchmarks: {$this->countBenchmarks($benchmarkResults)}

HTML; // Add benchmark results if (!empty($benchmarkResults)) { $html .= $this->generateBenchmarkSection($benchmarkResults); } // Add load test results if ($loadTestResult) { $html .= $this->generateLoadTestSection($loadTestResult); } $html .= << HTML; return $html; } /** * Generate JSON report */ public function generateJsonReport( array $benchmarkResults, ?LoadTestResult $loadTestResult = null ): string { $report = [ 'timestamp' => date('Y-m-d H:i:s'), 'benchmarks' => [] ]; foreach ($benchmarkResults as $category => $result) { $report['benchmarks'][$category] = $result->toArray(); } if ($loadTestResult) { $report['load_test'] = $loadTestResult->toArray(); } return json_encode($report, JSON_PRETTY_PRINT); } /** * Generate markdown report */ public function generateMarkdownReport( array $benchmarkResults, ?LoadTestResult $loadTestResult = null ): string { $markdown = "# Performance Test Report\n\n"; $markdown .= "_Generated: " . $this->getCurrentTimestamp() . "_\n\n"; // Benchmark results if (!empty($benchmarkResults)) { $markdown .= "## Benchmarks\n\n"; foreach ($benchmarkResults as $category => $result) { $markdown .= "### {$result->name}\n\n"; $markdown .= "| Metric | Value |\n"; $markdown .= "|--------|-------|\n"; $markdown .= "| Iterations | {$result->iterations} |\n"; $markdown .= "| Avg Time | {$result->avgTimeMs}ms |\n"; $markdown .= "| Min Time | {$result->minTimeMs}ms |\n"; $markdown .= "| Max Time | {$result->maxTimeMs}ms |\n"; $markdown .= "| Median Time | {$result->medianTimeMs}ms |\n"; $markdown .= "| P95 Time | {$result->p95TimeMs}ms |\n"; $markdown .= "| P99 Time | {$result->p99TimeMs}ms |\n"; $markdown .= "| Ops/Sec | " . round($result->operationsPerSecond, 2) . " |\n"; $markdown .= "\n"; } } // Load test results if ($loadTestResult) { $markdown .= "## Load Test Results\n\n"; $markdown .= "| Metric | Value |\n"; $markdown .= "|--------|-------|\n"; $markdown .= "| Total Requests | {$loadTestResult->totalRequests} |\n"; $markdown .= "| Successful | {$loadTestResult->successfulRequests} |\n"; $markdown .= "| Error Rate | " . round($loadTestResult->errorRate, 2) . "% |\n"; $markdown .= "| Avg Response Time | " . round($loadTestResult->avgResponseTimeMs, 2) . "ms |\n"; $markdown .= "| P95 Response Time | " . round($loadTestResult->p95ResponseTimeMs, 2) . "ms |\n"; $markdown .= "| Throughput | " . round($loadTestResult->requestsPerSecond, 2) . " req/sec |\n"; } return $markdown; } /** * Save report to file */ public function saveReport(string $content, string $filename): void { $reportsDir = __DIR__ . '/../Reports'; if (!is_dir($reportsDir)) { mkdir($reportsDir, 0755, true); } $filepath = $reportsDir . '/' . $filename; file_put_contents($filepath, $content); } private function generateBenchmarkSection(array $benchmarkResults): string { $html = "

Benchmark Results

\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; foreach ($benchmarkResults as $category => $result) { $colorClass = $this->getColorClass($result->avgTimeMs); $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; } $html .= "\n"; $html .= "
BenchmarkIterationsAvg TimeMinMaxP95Ops/Sec
{$result->name}{$result->iterations}" . round($result->avgTimeMs, 2) . "ms" . round($result->minTimeMs, 2) . "ms" . round($result->maxTimeMs, 2) . "ms" . round($result->p95TimeMs, 2) . "ms" . round($result->operationsPerSecond, 2) . "
\n"; return $html; } private function generateLoadTestSection(LoadTestResult $result): string { $html = "

Load Test Results

\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "
MetricValue
Total Requests{$result->totalRequests}
Successful Requests{$result->successfulRequests}
Error Rate" . round($result->errorRate, 2) . "%
Avg Response Time" . round($result->avgResponseTimeMs, 2) . "ms
P95 Response Time" . round($result->p95ResponseTimeMs, 2) . "ms
P99 Response Time" . round($result->p99ResponseTimeMs, 2) . "ms
Throughput" . round($result->requestsPerSecond, 2) . " req/sec
\n"; return $html; } private function getColorClass(float $timeMs): string { if ($timeMs < 10) { return 'good'; } elseif ($timeMs < 50) { return 'warning'; } return 'bad'; } private function getCurrentTimestamp(): string { return date('Y-m-d H:i:s'); } private function countBenchmarks(array $benchmarkResults): int { return count($benchmarkResults); } }