返回 Skill 列表
extension
分类: 开发与工程无需 API Key

libperf

libperf - 性能测试工具。benchmark函数用于测量执行时间和内存。validateDuration和validateMemory断言性能约束。ScalingAnalyzer检测线性与次线性扩展。PerfRunner编排基准测试套件。可用于性能测试、基准测试以及检测性能退化。

person作者: jakexiaohubgithub

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

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

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.