AgentSkillsCN

libperf

libperf——性能测试实用工具。benchmark 函数可测量执行时间和内存占用。validateDuration 与 validateMemory 可用于断言性能约束。ScalingAnalyzer 能够检测线性与亚线性扩展之间的差异。PerfRunner 可协调基准测试套件。适用于性能测试、基准评测,以及性能回归的检测。

SKILL.md
--- frontmatter
name: libperf
description: >
  libperf - Performance testing utilities. benchmark function measures execution
  time and memory. validateDuration and validateMemory assert performance
  constraints. ScalingAnalyzer detects linear vs sublinear scaling. PerfRunner
  orchestrates benchmark suites. Use for performance testing, benchmarking, and
  detecting performance regressions.

libperf Skill

When to Use

  • Writing performance tests for critical code paths
  • Benchmarking function execution time and memory
  • Detecting performance regressions in CI
  • Validating scaling characteristics (O(n) vs O(n²))

Key Concepts

benchmark: Runs a function multiple times and collects timing/memory stats.

validateDuration/validateMemory: Assert that benchmarks meet performance requirements.

ScalingAnalyzer: Analyzes how performance scales with input size.

Usage Patterns

Pattern 1: Basic benchmark

javascript
import { benchmark, validateDuration } from "@copilot-ld/libperf";

const result = await benchmark(
  async () => {
    await myFunction(input);
  },
  { iterations: 100 },
);

validateDuration(result, 50); // Assert max 50ms

Pattern 2: Scaling analysis

javascript
import { ScalingAnalyzer } from "@copilot-ld/libperf";

const analyzer = new ScalingAnalyzer();
const scaling = await analyzer.analyze(fn, [100, 1000, 10000]);
// scaling.type: "linear" | "sublinear" | "superlinear"

Integration

Performance tests use .perf.js extension. Run via npm run test:perf.