AgentSkillsCN

julia-bench-write

使用BenchmarkTools.jl为Julia软件包编写基准测试套件。当您需要创建条理清晰、可重复验证的基准测试套件时,此技能将为您提供有力支持。

SKILL.md
--- frontmatter
name: julia-bench-write
description: Write benchmark suites for Julia packages using BenchmarkTools.jl. Use this skill when creating organized, reproducible benchmark suites.

Writing Julia Benchmark Suites

Write organized benchmark suites for Julia packages using BenchmarkTools.jl with reproducible data and grouped benchmarks.

Project Structure

code
MyPackage.jl/
├── Project.toml           # Must include benchmark in workspace
├── benchmark/
│   ├── Project.toml       # Benchmark dependencies
│   └── benchmarks.jl      # Benchmark suite definition

Workspace Configuration

toml
# Project.toml
[workspace]
projects = ["docs", "benchmark"]

Benchmark Dependencies

benchmark/Project.toml

toml
[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
MyPackage = "your-package-uuid"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"

Basic Suite Structure

benchmark/benchmarks.jl

julia
using BenchmarkTools
using MyPackage
using StableRNGs

const SUITE = BenchmarkGroup()
rng = StableRNG(42)

# Pre-create constant test data
const test_data = generate_data(rng, 1000)

# Define benchmarks
SUITE["operations"] = BenchmarkGroup()
SUITE["operations"]["process"] = @benchmarkable process($test_data)
SUITE["inplace"]["modify"] = @benchmarkable modify!(d) setup=(d=copy($test_data)) evals=1

Quick Reference

PatternUse Case
@benchmarkable f($x)Pure function
@benchmarkable f!(y) setup=(y=copy(x)) evals=1Mutating function
SUITE["group"]["name"]Organization
StableRNG(seed)Reproducible random

Reference

Related Skills

  • julia-bench-quick - Quick impromptu benchmarks
  • julia-bench-run - Running benchmark suites