Files
proffesor-for-testing__agen…/tests/performance-benchmark.ts
Profa b91627f282 fix(quality): implement GOAP Issue #149 code quality remediation
Phase 1: Test Determinism
- Create SeededRandom utility with Mulberry32 PRNG (src/utils/SeededRandom.ts)
- Migrate 258+ Math.random() calls to SeededRandom across 65+ test files
- Add timer test utilities (tests/helpers/timerTestUtils.ts)
- Add jest.useFakeTimers() pattern to 13 test files

Phase 2: Type Safety (63.5% reduction)
- Reduce `any` types from ~1,800 to 656
- Add 50+ new interfaces across agents, core, mcp, cli modules
- Fix all TypeScript errors (0 errors, build passes)
- Replace Record<string, any> with Record<string, unknown>
- Add proper type guards for hook methods (PostTaskData, TaskErrorData)

Key improvements:
- agents/: 105 → 0 any types (100% reduction)
- mcp/: 226 → 102 any types (55% reduction)
- cli/: 277 → 168 any types (39% reduction)
- core/: 199 → 175 any types (12% reduction)

Closes #149

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 17:08:12 +00:00

836 lines
29 KiB
TypeScript

#!/usr/bin/env ts-node
/**
* AQE Fleet Performance Benchmark Suite
*
* Comprehensive performance analysis for O(log n) algorithm verification,
* memory usage patterns, and concurrent operation limits.
*/
import { performance } from 'perf_hooks';
import { execSync } from 'child_process';
import { EventBus } from '../src/core/EventBus';
import { FleetManager } from '../src/core/FleetManager';
import { MemoryManager } from '../src/core/MemoryManager';
import { Agent, AgentStatus } from '../src/core/Agent';
import { Task, TaskStatus } from '../src/core/Task';
import { v4 as uuidv4 } from 'uuid';
import { createSeededRandom } from '../src/utils/SeededRandom';
interface BenchmarkResult {
name: string;
duration: number;
operations: number;
throughput: number;
memoryUsage: NodeJS.MemoryUsage;
complexity?: string;
metrics?: any;
}
interface PerformanceMetrics {
agentInitialization: BenchmarkResult[];
memoryOperations: BenchmarkResult[];
eventBusPerformance: BenchmarkResult[];
taskExecution: BenchmarkResult[];
concurrentOperations: BenchmarkResult[];
sublinearVerification: BenchmarkResult[];
}
class PerformanceBenchmarker {
private results: PerformanceMetrics;
private testSizes: number[] = [10, 50, 100, 500, 1000, 5000];
constructor() {
this.results = {
agentInitialization: [],
memoryOperations: [],
eventBusPerformance: [],
taskExecution: [],
concurrentOperations: [],
sublinearVerification: []
};
}
/**
* Run all benchmark suites
*/
async runAllBenchmarks(): Promise<PerformanceMetrics> {
console.log('🚀 Starting AQE Fleet Performance Benchmark Suite...\n');
try {
await this.benchmarkAgentInitialization();
await this.benchmarkMemoryOperations();
await this.benchmarkEventBusPerformance();
await this.benchmarkTaskExecution();
await this.benchmarkConcurrentOperations();
await this.verifySublinearPerformance();
return this.results;
} catch (error) {
console.error('❌ Benchmark suite failed:', error);
throw error;
}
}
/**
* Benchmark agent initialization performance
*/
async benchmarkAgentInitialization(): Promise<void> {
console.log('📊 Benchmarking Agent Initialization Performance...');
for (const size of this.testSizes) {
const startTime = performance.now();
const initialMemory = process.memoryUsage();
// Create fleet manager with agents
const fleetConfig = {
agents: [
{ type: 'test-generator', count: Math.floor(size * 0.3), config: {} },
{ type: 'test-executor', count: Math.floor(size * 0.3), config: {} },
{ type: 'coverage-analyzer', count: Math.floor(size * 0.2), config: {} },
{ type: 'quality-gate', count: Math.floor(size * 0.2), config: {} }
]
};
const fleetManager = new FleetManager(fleetConfig);
try {
await fleetManager.initialize();
await fleetManager.start();
const endTime = performance.now();
const finalMemory = process.memoryUsage();
const duration = endTime - startTime;
this.results.agentInitialization.push({
name: `Initialize ${size} agents`,
duration,
operations: size,
throughput: size / (duration / 1000),
memoryUsage: {
rss: finalMemory.rss - initialMemory.rss,
heapUsed: finalMemory.heapUsed - initialMemory.heapUsed,
heapTotal: finalMemory.heapTotal - initialMemory.heapTotal,
external: finalMemory.external - initialMemory.external,
arrayBuffers: finalMemory.arrayBuffers - initialMemory.arrayBuffers
},
complexity: 'O(n)',
metrics: {
agentsPerSecond: size / (duration / 1000),
memoryPerAgent: (finalMemory.rss - initialMemory.rss) / size,
initializationLatency: duration / size
}
});
await fleetManager.stop();
console.log(` ✅ ${size} agents initialized in ${duration.toFixed(2)}ms`);
// Force garbage collection if available
if (global.gc) {
global.gc();
}
// Wait to allow cleanup
await new Promise(resolve => setTimeout(resolve, 100));
} catch (error) {
console.error(` ❌ Failed to initialize ${size} agents:`, error);
}
}
}
/**
* Benchmark memory operations
*/
async benchmarkMemoryOperations(): Promise<void> {
console.log('\n💾 Benchmarking Memory Operations...');
const memoryManager = new MemoryManager();
await memoryManager.initialize();
// Test different operation types
const operations = ['store', 'retrieve', 'search', 'delete'];
for (const operation of operations) {
for (const size of this.testSizes) {
const startTime = performance.now();
const initialMemory = process.memoryUsage();
switch (operation) {
case 'store':
for (let i = 0; i < size; i++) {
await memoryManager.store(
`test-key-${i}`,
{ data: `test-data-${i}`, index: i },
{ namespace: 'benchmark', ttl: 3600000 }
);
}
break;
case 'retrieve':
// Pre-populate for retrieval test
for (let i = 0; i < size; i++) {
await memoryManager.store(
`retrieve-key-${i}`,
{ data: `test-data-${i}` },
{ namespace: 'benchmark' }
);
}
// Measure retrieval
const retrieveStart = performance.now();
for (let i = 0; i < size; i++) {
await memoryManager.retrieve(`retrieve-key-${i}`, 'benchmark');
}
const retrieveEnd = performance.now();
this.recordResult('memoryOperations', {
name: `${operation} ${size} items`,
duration: retrieveEnd - retrieveStart,
operations: size,
throughput: size / ((retrieveEnd - retrieveStart) / 1000),
memoryUsage: this.getMemoryDelta(initialMemory),
complexity: 'O(1) average, O(log n) with tree storage'
});
continue;
case 'search':
// Pre-populate for search test
for (let i = 0; i < size; i++) {
await memoryManager.store(
`search-key-${i}`,
{ data: `searchable-content-${i % 10}` },
{ namespace: 'benchmark' }
);
}
// Measure search
const searchStart = performance.now();
await memoryManager.search({
namespace: 'benchmark',
pattern: 'searchable-content',
limit: size
});
const searchEnd = performance.now();
this.recordResult('memoryOperations', {
name: `${operation} ${size} items`,
duration: searchEnd - searchStart,
operations: size,
throughput: size / ((searchEnd - searchStart) / 1000),
memoryUsage: this.getMemoryDelta(initialMemory),
complexity: 'O(n) linear search, could be O(log n) with indexing'
});
continue;
case 'delete':
// Pre-populate for deletion test
for (let i = 0; i < size; i++) {
await memoryManager.store(
`delete-key-${i}`,
{ data: `test-data-${i}` },
{ namespace: 'benchmark' }
);
}
// Measure deletion
const deleteStart = performance.now();
for (let i = 0; i < size; i++) {
await memoryManager.delete(`delete-key-${i}`, 'benchmark');
}
const deleteEnd = performance.now();
this.recordResult('memoryOperations', {
name: `${operation} ${size} items`,
duration: deleteEnd - deleteStart,
operations: size,
throughput: size / ((deleteEnd - deleteStart) / 1000),
memoryUsage: this.getMemoryDelta(initialMemory),
complexity: 'O(1) average'
});
continue;
}
const endTime = performance.now();
const finalMemory = process.memoryUsage();
const duration = endTime - startTime;
this.results.memoryOperations.push({
name: `${operation} ${size} items`,
duration,
operations: size,
throughput: size / (duration / 1000),
memoryUsage: {
rss: finalMemory.rss - initialMemory.rss,
heapUsed: finalMemory.heapUsed - initialMemory.heapUsed,
heapTotal: finalMemory.heapTotal - initialMemory.heapTotal,
external: finalMemory.external - initialMemory.external,
arrayBuffers: finalMemory.arrayBuffers - initialMemory.arrayBuffers
},
complexity: operation === 'search' ? 'O(n)' : 'O(1) average'
});
console.log(` ✅ ${operation} ${size} items in ${duration.toFixed(2)}ms`);
}
}
await memoryManager.shutdown();
}
/**
* Benchmark event bus performance
*/
async benchmarkEventBusPerformance(): Promise<void> {
console.log('\n🔄 Benchmarking Event Bus Performance...');
const eventBus = new EventBus();
await eventBus.initialize();
for (const size of this.testSizes) {
const startTime = performance.now();
const initialMemory = process.memoryUsage();
// Setup event listeners
const receivedEvents: any[] = [];
eventBus.on('benchmark-event', (data) => {
receivedEvents.push(data);
});
// Emit events
const emitPromises: Promise<string>[] = [];
for (let i = 0; i < size; i++) {
emitPromises.push(
eventBus.emitFleetEvent(
'benchmark-event',
`source-${i}`,
{ index: i, timestamp: Date.now() }
)
);
}
await Promise.all(emitPromises);
// Wait for all events to be processed
await new Promise(resolve => setTimeout(resolve, 100));
const endTime = performance.now();
const finalMemory = process.memoryUsage();
const duration = endTime - startTime;
this.results.eventBusPerformance.push({
name: `Process ${size} events`,
duration,
operations: size,
throughput: size / (duration / 1000),
memoryUsage: {
rss: finalMemory.rss - initialMemory.rss,
heapUsed: finalMemory.heapUsed - initialMemory.heapUsed,
heapTotal: finalMemory.heapTotal - initialMemory.heapTotal,
external: finalMemory.external - initialMemory.external,
arrayBuffers: finalMemory.arrayBuffers - initialMemory.arrayBuffers
},
complexity: 'O(1) per event emit, O(n) for listeners',
metrics: {
eventsPerSecond: size / (duration / 1000),
eventsReceived: receivedEvents.length,
deliveryRate: receivedEvents.length / size,
averageLatency: duration / size
}
});
console.log(` ✅ ${size} events processed in ${duration.toFixed(2)}ms (${receivedEvents.length} received)`);
// Cleanup
eventBus.removeAllListeners('benchmark-event');
}
}
/**
* Benchmark task execution performance
*/
async benchmarkTaskExecution(): Promise<void> {
console.log('\n⚡ Benchmarking Task Execution Performance...');
// Create a minimal test agent for benchmarking
class BenchmarkAgent extends Agent {
protected async onInitialize(): Promise<void> {
this.capabilities = [{
name: 'benchmark',
version: '1.0.0',
description: 'Benchmark task execution',
taskTypes: ['benchmark']
}];
}
protected async onStart(): Promise<void> {}
protected async onStop(): Promise<void> {}
protected async executeTaskLogic(task: Task): Promise<any> {
// Simulate some work
const complexity = task.getData().complexity || 1;
let result = 0;
for (let i = 0; i < complexity; i++) {
result += Math.sqrt(i);
}
return { result, operations: complexity };
}
protected async initializeCapabilities(): Promise<void> {}
}
const eventBus = new EventBus();
await eventBus.initialize();
for (const size of this.testSizes) {
const startTime = performance.now();
const initialMemory = process.memoryUsage();
// Create agent
const agent = new BenchmarkAgent(uuidv4(), 'benchmark', {}, eventBus);
await agent.initialize();
await agent.start();
// Create and execute tasks
const taskPromises: Promise<void>[] = [];
for (let i = 0; i < size; i++) {
const task = new Task(
uuidv4(),
'benchmark',
{ complexity: 1000, index: i },
1 // priority
);
taskPromises.push(agent.assignTask(task));
}
await Promise.all(taskPromises);
await agent.stop();
const endTime = performance.now();
const finalMemory = process.memoryUsage();
const duration = endTime - startTime;
this.results.taskExecution.push({
name: `Execute ${size} tasks`,
duration,
operations: size,
throughput: size / (duration / 1000),
memoryUsage: {
rss: finalMemory.rss - initialMemory.rss,
heapUsed: finalMemory.heapUsed - initialMemory.heapUsed,
heapTotal: finalMemory.heapTotal - initialMemory.heapTotal,
external: finalMemory.external - initialMemory.external,
arrayBuffers: finalMemory.arrayBuffers - initialMemory.arrayBuffers
},
complexity: 'O(n) sequential execution',
metrics: {
tasksPerSecond: size / (duration / 1000),
averageTaskTime: duration / size,
agentMetrics: agent.getMetrics()
}
});
console.log(` ✅ ${size} tasks executed in ${duration.toFixed(2)}ms`);
}
}
/**
* Benchmark concurrent operations
*/
async benchmarkConcurrentOperations(): Promise<void> {
console.log('\n🔄 Benchmarking Concurrent Operations...');
const concurrencyLevels = [1, 2, 4, 8, 16, 32];
for (const concurrency of concurrencyLevels) {
const startTime = performance.now();
const initialMemory = process.memoryUsage();
const eventBus = new EventBus();
await eventBus.initialize();
// Create multiple memory managers for concurrent access
const memoryManagers = await Promise.all(
Array(concurrency).fill(0).map(async () => {
const manager = new MemoryManager();
await manager.initialize();
return manager;
})
);
// Perform concurrent operations
const operationsPerManager = 100;
const concurrentPromises = memoryManagers.map(async (manager, index) => {
const ops: Promise<any>[] = [];
for (let i = 0; i < operationsPerManager; i++) {
ops.push(manager.store(
`concurrent-${index}-${i}`,
{ managerIndex: index, operationIndex: i },
{ namespace: 'concurrent' }
));
}
return Promise.all(ops);
});
await Promise.all(concurrentPromises);
// Cleanup
await Promise.all(memoryManagers.map(manager => manager.shutdown()));
const endTime = performance.now();
const finalMemory = process.memoryUsage();
const duration = endTime - startTime;
const totalOperations = concurrency * operationsPerManager;
this.results.concurrentOperations.push({
name: `${concurrency} concurrent workers`,
duration,
operations: totalOperations,
throughput: totalOperations / (duration / 1000),
memoryUsage: {
rss: finalMemory.rss - initialMemory.rss,
heapUsed: finalMemory.heapUsed - initialMemory.heapUsed,
heapTotal: finalMemory.heapTotal - initialMemory.heapTotal,
external: finalMemory.external - initialMemory.external,
arrayBuffers: finalMemory.arrayBuffers - initialMemory.arrayBuffers
},
complexity: 'O(n/p) where p is concurrency level',
metrics: {
concurrencyLevel: concurrency,
operationsPerWorker: operationsPerManager,
parallelEfficiency: (totalOperations / (duration / 1000)) / concurrency
}
});
console.log(` ✅ ${totalOperations} operations with ${concurrency} workers in ${duration.toFixed(2)}ms`);
}
}
/**
* Verify sublinear performance claims
*/
async verifySublinearPerformance(): Promise<void> {
console.log('\n📈 Verifying Sublinear Performance Claims...');
// Test different data structures and algorithms for sublinear behavior
const algorithms = [
{ name: 'Binary Search Simulation', complexity: 'O(log n)' },
{ name: 'Hash Table Operations', complexity: 'O(1) average' },
{ name: 'Tree Operations', complexity: 'O(log n)' }
];
// Seeded RNG for reproducible sublinear verification (seed: 16000)
const rng = createSeededRandom(16000);
for (const algorithm of algorithms) {
console.log(` Testing ${algorithm.name}...`);
const measurementPoints: { size: number; time: number }[] = [];
for (const size of this.testSizes) {
const startTime = performance.now();
switch (algorithm.name) {
case 'Binary Search Simulation':
// Simulate binary search on sorted array
const sortedArray = Array.from({ length: size }, (_, i) => i);
for (let i = 0; i < 100; i++) {
const target = Math.floor(rng.random() * size);
this.binarySearch(sortedArray, target);
}
break;
case 'Hash Table Operations':
// Simulate hash table operations
const map = new Map();
for (let i = 0; i < size; i++) {
map.set(`key-${i}`, `value-${i}`);
}
for (let i = 0; i < 100; i++) {
const key = `key-${Math.floor(rng.random() * size)}`;
map.get(key);
}
break;
case 'Tree Operations':
// Simulate balanced tree operations (using approximation)
const operations = Math.floor(Math.log2(size)) * 100;
for (let i = 0; i < operations; i++) {
// Simulate tree traversal cost
let depth = 0;
let current = size;
while (current > 1) {
current = Math.floor(current / 2);
depth++;
}
}
break;
}
const endTime = performance.now();
const duration = endTime - startTime;
measurementPoints.push({ size, time: duration });
console.log(` ✅ Size ${size}: ${duration.toFixed(2)}ms`);
}
// Analyze complexity growth
const complexityAnalysis = this.analyzeComplexityGrowth(measurementPoints);
this.results.sublinearVerification.push({
name: algorithm.name,
duration: measurementPoints.reduce((sum, p) => sum + p.time, 0),
operations: measurementPoints.length,
throughput: 0, // Not applicable for complexity analysis
memoryUsage: process.memoryUsage(),
complexity: algorithm.complexity,
metrics: {
theoreticalComplexity: algorithm.complexity,
measuredGrowthRate: complexityAnalysis.growthRate,
correlationCoefficient: complexityAnalysis.correlation,
isSublinear: complexityAnalysis.isSublinear,
measurementPoints
}
});
}
}
/**
* Binary search implementation for testing
*/
private binarySearch(arr: number[], target: number): number {
let left = 0;
let right = arr.length - 1;
while (left <= right) {
const mid = Math.floor((left + right) / 2);
if (arr[mid] === target) return mid;
if (arr[mid] < target) left = mid + 1;
else right = mid - 1;
}
return -1;
}
/**
* Analyze complexity growth from measurement points
*/
private analyzeComplexityGrowth(points: { size: number; time: number }[]): {
growthRate: number;
correlation: number;
isSublinear: boolean;
} {
if (points.length < 3) {
return { growthRate: 0, correlation: 0, isSublinear: false };
}
// Calculate growth rate using linear regression on log-log scale
const logSizes = points.map(p => Math.log(p.size));
const logTimes = points.map(p => Math.log(p.time));
const n = points.length;
const sumLogSize = logSizes.reduce((sum, x) => sum + x, 0);
const sumLogTime = logTimes.reduce((sum, y) => sum + y, 0);
const sumLogSizeLogTime = logSizes.reduce((sum, x, i) => sum + x * logTimes[i], 0);
const sumLogSizeSquared = logSizes.reduce((sum, x) => sum + x * x, 0);
const growthRate = (n * sumLogSizeLogTime - sumLogSize * sumLogTime) /
(n * sumLogSizeSquared - sumLogSize * sumLogSize);
// Calculate correlation coefficient
const meanLogSize = sumLogSize / n;
const meanLogTime = sumLogTime / n;
const numerator = logSizes.reduce((sum, x, i) => sum + (x - meanLogSize) * (logTimes[i] - meanLogTime), 0);
const denominator = Math.sqrt(
logSizes.reduce((sum, x) => sum + (x - meanLogSize) ** 2, 0) *
logTimes.reduce((sum, y) => sum + (y - meanLogTime) ** 2, 0)
);
const correlation = numerator / denominator;
// Consider sublinear if growth rate < 1.0 (less than linear)
const isSublinear = growthRate < 1.0;
return { growthRate, correlation, isSublinear };
}
/**
* Helper method to record benchmark results
*/
private recordResult(category: keyof PerformanceMetrics, result: BenchmarkResult): void {
this.results[category].push(result);
}
/**
* Helper method to calculate memory delta
*/
private getMemoryDelta(initial: NodeJS.MemoryUsage): NodeJS.MemoryUsage {
const current = process.memoryUsage();
return {
rss: current.rss - initial.rss,
heapUsed: current.heapUsed - initial.heapUsed,
heapTotal: current.heapTotal - initial.heapTotal,
external: current.external - initial.external,
arrayBuffers: current.arrayBuffers - initial.arrayBuffers
};
}
/**
* Generate comprehensive performance report
*/
generateReport(): string {
const report = [
'# AQE Fleet Performance Benchmark Report',
`Generated at: ${new Date().toISOString()}`,
`Node.js version: ${process.version}`,
`Platform: ${process.platform} ${process.arch}`,
'',
'## Executive Summary',
''
];
// Analyze each category
for (const [category, results] of Object.entries(this.results)) {
if (results.length === 0) continue;
report.push(`### ${category.replace(/([A-Z])/g, ' $1').replace(/^./, str => str.toUpperCase())}`);
report.push('');
const avgThroughput = results.reduce((sum, r) => sum + r.throughput, 0) / results.length;
const avgDuration = results.reduce((sum, r) => sum + r.duration, 0) / results.length;
const maxThroughput = Math.max(...results.map(r => r.throughput));
report.push(`- Average Throughput: ${avgThroughput.toFixed(2)} ops/sec`);
report.push(`- Average Duration: ${avgDuration.toFixed(2)}ms`);
report.push(`- Peak Throughput: ${maxThroughput.toFixed(2)} ops/sec`);
report.push('');
// Detailed results table
report.push('| Test Case | Duration (ms) | Throughput (ops/sec) | Complexity |');
report.push('|-----------|---------------|---------------------|------------|');
for (const result of results) {
report.push(
`| ${result.name} | ${result.duration.toFixed(2)} | ${result.throughput.toFixed(2)} | ${result.complexity || 'N/A'} |`
);
}
report.push('');
}
// O(log n) Verification Section
const sublinearResults = this.results.sublinearVerification;
if (sublinearResults.length > 0) {
report.push('## O(log n) Algorithm Verification');
report.push('');
for (const result of sublinearResults) {
const metrics = result.metrics;
report.push(`### ${result.name}`);
report.push(`- Theoretical Complexity: ${metrics.theoreticalComplexity}`);
report.push(`- Measured Growth Rate: ${metrics.measuredGrowthRate.toFixed(3)}`);
report.push(`- Correlation Coefficient: ${metrics.correlationCoefficient.toFixed(3)}`);
report.push(`- Is Sublinear: ${metrics.isSublinear ? '✅ YES' : '❌ NO'}`);
report.push('');
}
}
// Performance Bottlenecks
report.push('## Performance Bottlenecks');
report.push('');
const allResults = Object.values(this.results).flat();
const slowestOperations = allResults
.sort((a, b) => a.throughput - b.throughput)
.slice(0, 5);
report.push('Top 5 Slowest Operations:');
for (let i = 0; i < slowestOperations.length; i++) {
const op = slowestOperations[i];
report.push(`${i + 1}. ${op.name}: ${op.throughput.toFixed(2)} ops/sec`);
}
report.push('');
// Memory Usage Analysis
report.push('## Memory Usage Analysis');
report.push('');
const memoryResults = allResults.filter(r => r.memoryUsage);
if (memoryResults.length > 0) {
const avgMemoryGrowth = memoryResults.reduce((sum, r) => sum + r.memoryUsage.heapUsed, 0) / memoryResults.length;
const maxMemoryGrowth = Math.max(...memoryResults.map(r => r.memoryUsage.heapUsed));
report.push(`- Average Heap Growth: ${(avgMemoryGrowth / 1024 / 1024).toFixed(2)} MB`);
report.push(`- Max Heap Growth: ${(maxMemoryGrowth / 1024 / 1024).toFixed(2)} MB`);
report.push('');
}
// Recommendations
report.push('## Recommendations');
report.push('');
// Analyze results for recommendations
const hasSlowMemoryOps = this.results.memoryOperations.some(r => r.throughput < 1000);
const hasSlowEventBus = this.results.eventBusPerformance.some(r => r.throughput < 5000);
const hasMemoryLeaks = memoryResults.some(r => r.memoryUsage.heapUsed > 100 * 1024 * 1024);
if (hasSlowMemoryOps) {
report.push('- ⚠️ Memory operations show suboptimal performance - consider implementing B-tree indexing for O(log n) search');
}
if (hasSlowEventBus) {
report.push('- ⚠️ Event bus throughput is below optimal - consider connection pooling and event batching');
}
if (hasMemoryLeaks) {
report.push('- ⚠️ High memory usage detected - review object lifecycle and implement better cleanup');
}
const sublinearAlgorithms = sublinearResults.filter(r => r.metrics.isSublinear);
if (sublinearAlgorithms.length > 0) {
report.push(`- ✅ ${sublinearAlgorithms.length} algorithms verified as sublinear - performance claims confirmed`);
}
return report.join('\n');
}
}
// Main execution function
async function main() {
const benchmarker = new PerformanceBenchmarker();
try {
console.log('🎯 AQE Fleet Performance Tester Agent Starting...\n');
// Run all benchmarks
const results = await benchmarker.runAllBenchmarks();
// Generate report
const report = benchmarker.generateReport();
console.log('\n📊 Performance Benchmark Complete!\n');
console.log(report);
// Store results in coordination memory
try {
const storeCommand = `npx claude-flow@alpha memory store --namespace "aqe-analysis" --key "performance-metrics" --value '${JSON.stringify(results, null, 2).replace(/'/g, "\\'")}' --ttl 3600000`;
console.log('\n💾 Storing performance metrics in coordination memory...');
execSync(storeCommand, { stdio: 'inherit' });
// SECURITY FIX: Properly escape backslashes first, then single quotes
const reportCommand = `npx claude-flow@alpha memory store --namespace "aqe-analysis" --key "performance-report" --value '${report.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}' --ttl 3600000`;
execSync(reportCommand, { stdio: 'inherit' });
console.log('✅ Performance data stored in coordination memory');
} catch (error) {
console.warn('⚠️ Failed to store in coordination memory:', error);
}
// Exit with success
process.exit(0);
} catch (error) {
console.error('❌ Performance benchmark failed:', error);
process.exit(1);
}
}
// Run if called directly
if (require.main === module) {
main().catch(console.error);
}
export { PerformanceBenchmarker, PerformanceMetrics, BenchmarkResult };