Files
proffesor-for-testing__agen…/tests/benchmarks/task-queue-sorting.bench.ts
Profa 2253d05618 feat: flatten project structure — archive v2, promote v3 to root
Remove the nested v3/ subdirectory by moving all active source code,
tests, configs, and assets directly to the project root. Archive v2/
(dead code, 847MB) to v2-archive.tar.gz.

Key changes:
- Move v3/src/ → src/, v3/tests/ → tests/, v3/packages/ → packages/
- Move v3/tsconfig.json, v3/vitest.config.ts to root
- Merge v3/package.json into root package.json (ESM, scripts, deps, exports)
- Merge v3/scripts/ into scripts/, v3/implementation/ into docs/implementation/
- Update all CI workflows to remove "cd v3 &&" and v3/ path prefixes
- Fix all init installer path resolution (3-level-up → 2-level-up)
- Fix hooks to use "node ./dist/cli/bundle.js" instead of bare "aqe"
- Update settings.json ADR/DDD directories to docs/implementation/
- Fix helper scripts (statusline, adr-compliance, ddd-tracker, guidance-hooks)
- Update 58 agent definitions: aqe/v3/ → aqe/ memory namespaces
- Update 15 guidance shards: v3/src/ → src/ path references
- Fix sync interfaces: remove v3/ and v2/ path references
- Fix test path calculations (process.cwd() + '..' no longer needed)
- Fix flaky perf test threshold (500ms → 1000ms for CI environments)
- Fix complexity-analyzer test to match ADR-051 keyword-based eligibility

Build passes, 17,901 tests pass, CLI and MCP bundles verified.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 11:35:41 +00:00

99 lines
2.9 KiB
TypeScript

/**
* Benchmark: Task Queue Sorting Performance
*
* Compares O(n log n) sort approach vs O(log n) binary insertion
* for the Queen Coordinator's task queue.
*
* Run with: npx vitest bench tests/benchmarks/task-queue-sorting.bench.ts
*/
import { describe, bench } from 'vitest';
import { binaryInsert, createdAtComparator } from '../../src/shared/utils/binary-insert';
interface QueenTask {
id: string;
priority: 'p0' | 'p1' | 'p2' | 'p3';
createdAt: Date;
type: string;
}
const taskComparator = createdAtComparator<QueenTask>();
function createTasks(count: number): QueenTask[] {
const baseTime = Date.now();
return Array.from({ length: count }, (_, i) => ({
id: `task_${i}`,
priority: ['p0', 'p1', 'p2', 'p3'][i % 4] as QueenTask['priority'],
createdAt: new Date(baseTime + Math.random() * 10000),
type: 'test-task',
}));
}
// Old approach: push + sort on every insertion
function enqueueWithSort(queue: QueenTask[], task: QueenTask): void {
queue.push(task);
queue.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
}
// New approach: binary insertion (O(log n) search + O(n) insert)
function enqueueWithBinaryInsert(queue: QueenTask[], task: QueenTask): void {
binaryInsert(queue, task, taskComparator);
}
describe('Task Queue Enqueue Performance', () => {
const sizes = [100, 500, 1000];
for (const size of sizes) {
describe(`${size} tasks`, () => {
bench('OLD: push + sort (O(n log n) per insert)', () => {
const queue: QueenTask[] = [];
const tasks = createTasks(size);
for (const task of tasks) {
enqueueWithSort(queue, task);
}
});
bench('NEW: binary insert (O(log n) search)', () => {
const queue: QueenTask[] = [];
const tasks = createTasks(size);
for (const task of tasks) {
enqueueWithBinaryInsert(queue, task);
}
});
});
}
});
describe('Single Insertion into Existing Queue', () => {
const queueSizes = [100, 1000, 5000];
for (const queueSize of queueSizes) {
describe(`Queue size ${queueSize}`, () => {
const baseTime = Date.now();
const existingTasks = Array.from({ length: queueSize }, (_, i) => ({
id: `task_${i}`,
priority: 'p1' as const,
createdAt: new Date(baseTime + i * 10),
type: 'test-task',
}));
const newTask: QueenTask = {
id: 'new_task',
priority: 'p0',
createdAt: new Date(baseTime + (queueSize / 2) * 10), // Insert in middle
type: 'urgent-task',
};
bench('OLD: push + sort', () => {
const queue = [...existingTasks];
enqueueWithSort(queue, newTask);
});
bench('NEW: binary insert', () => {
const queue = [...existingTasks];
enqueueWithBinaryInsert(queue, newTask);
});
});
}
});