Token导航 LogoToken导航TokenDH.com
开发只读github未标认证来源可访问许可证需确认审计通过

go-benchmark-testing进行基准测试

Agent Skill

用于辅助测试设计、自动化测试、用例整理和回归验证。它适合让 Agent 编写单元测试、端到端测试、测试计划或根据失败日志定位问题。使用时需要确认项目测试框架、运行命令和夹具数据,避免为了通过测试而改坏真实逻辑;涉及浏览器或外部服务时,应区分本地模拟、测试环境和生产环境。

总安装

681

周安装

8

GitHub Stars

1

下载量

65
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:go-benchmark-testing(进行基准测试)
来源仓库:https://github.com/sentenz/skills
仓库路径:skills/go-benchmark-testing
安装命令:
npx skills add https://github.com/sentenz/skills --skill go-benchmark-testing
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/sentenz/skills --skill go-benchmark-testing

简介

用于辅助测试设计、用例整理和回归验证。

  • 适合编写单元测试、端到端测试或根据日志定位问题。
  • 使用时需确认项目测试框架和运行命令,避免改坏真实逻辑。
  • 涉及浏览器或外部服务时应区分本地模拟和生产环境。
  • go-benchmark-testing 属于开发类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Benchmark Testing

Instructions for AI coding agents on automating benchmark test creation using consistent software testing patterns in this Go project.

- 2.1. Microbenchmarking - 2.2. Comparative Benchmarking - 2.3. Memory Profiling - 2.4. Statistical Benchmarking - 2.5. Sub-benchmarks - 2.6. Table-Driven Testing

- 6.1. Multi-Scenario Benchmarks - 6.2. Simple Benchmarks - 6.3. Benchmarks with Validation

1. Benefits

  • Performance Measurement Benchmark tests measure the execution time and memory allocation of functions, providing quantifiable metrics for performance analysis.
  • Regression Detection Continuous benchmarking helps identify performance regressions early in the development cycle before they reach production.
  • Optimization Guidance Benchmark results guide optimization efforts by identifying bottlenecks and quantifying the impact of performance improvements.
  • Comparative Analysis Benchmarks enable comparison of different implementations or algorithms to make informed decisions about performance trade-offs.
  • Resource Profiling Memory allocation tracking helps identify unnecessary allocations and optimize memory usage patterns.

2. Patterns

2.1. Microbenchmarking

Microbenchmarking is a software testing technique that measures the performance of small, isolated code units to identify performance characteristics and bottlenecks.

2.2. Comparative Benchmarking

Comparative Benchmarking is a testing approach that compares the performance of different implementations or algorithms side-by-side using consistent workloads.

2.3. Memory Profiling

Memory Profiling is the process of measuring memory allocations and usage patterns during benchmark execution using -benchmem flag.

2.4. Statistical Benchmarking

Statistical Benchmarking uses multiple iterations to calculate statistical measures (mean, variance) to ensure reliable and reproducible results.

2.5. Sub-benchmarks

Sub-benchmarks organize related benchmark cases using b.Run() to group variations of the same function with different input scenarios.

2.6. Table-Driven Testing

Table-Driven Testing is a software testing technique in which benchmark cases are organized in a tabular format to systematically cover different input scenarios.

3. Workflow

  1. Identify Identify performance-critical functions in pkg/ or internal/ that benefit from performance tracking (e.g., pkg/<package>/<file>.go).
  2. Add/Create Create benchmark tests in the same package (e.g., pkg/<package>/<file>_test.go).
  3. Benchmark Test Coverage Requirements Focus on functions that:

- Are called frequently in hot paths - Perform mathematical operations or calculations - Process data structures or collections - Have multiple implementation approaches to compare - Are candidates for optimization

  1. Apply Templates Structure all benchmark tests using the template pattern.
  2. Baseline Measurements Establish performance baselines by running benchmarks on stable code before making changes.

4. Commands

CommandDescription
make go-test-benchExecute all benchmarks with memory statistics
go test -bench=BenchmarkPercent -benchmem./pkg/percentExecute a specific benchmark function
go test -bench=. -benchmem -cpuprofile=cpu.prof./pkg/percentGenerate CPU profile for performance analysis
go test -bench=. -benchmem -memprofile=mem.prof./pkg/percentGenerate memory profile for allocation analysis
go test -bench=. -benchtime=10s./pkg/percentRun benchmarks for a specific duration
benchstat old.txt new.txtCompare benchmark results before and after changes

5. Style Guide

  • Test Framework Use the standard Go testing package with testing.B for benchmark tests.
  • Include Imports Include testing and any packages needed for the function under test.
  • Benchmark Function Naming Name benchmark functions with the Benchmark prefix followed by the function name (e.g., BenchmarkPercent for testing Percent()).
  • Benchmark Loop Use b.Loop() to control the number of iterations. The testing framework automatically adjusts the loop iterations to get reliable timing measurements. b.Loop() is preferred over b.N as it provides better integration with the testing framework and more accurate measurements. Unlike b.N-style benchmarks, b.Loop() integrates timer management, it automatically handles b.ResetTimer() at the loop's start and b.StopTimer() at its end, eliminating the need to manually manage the benchmark timer for setup and cleanup code.
  • Timer Control When using b.Loop(), timer management is automatic and no manual b.ResetTimer(), b.StopTimer(), or b.StartTimer() calls are needed for typical benchmarks. For advanced scenarios not using b.Loop(), use b.ResetTimer() to exclude setup time from measurements and b.StopTimer()/b.StartTimer() to exclude specific operations.
  • Sub-benchmarks Use b.Run() to organize related benchmark cases with different input scenarios. Each sub-benchmark runs independently with its own b.N iterations.
  • Memory Reporting Use b.ReportAllocs() to report memory allocations per operation when not using -benchmem flag.
  • Result Validation Optionally validate results in benchmarks to prevent compiler optimizations from eliminating dead code.

6. Template

Use this template for new benchmark test functions. Replace placeholders with actual values and adjust as needed for the use case.

6.1. Multi-Scenario Benchmarks

For benchmarking multiple scenarios or input variations, use sub-benchmarks with table-driven approach.

func Benchmark<FunctionName>(b *testing.B) {
	// Define benchmark cases with different scenarios
	benchmarks := []struct {
		name   string
		param1 <type>
		param2 <type>
		// Add more parameters as needed
	}{
		{
			name:   "scenario description 1",
			param1: <value1>,
			param2: <value2>,
		},
		{
			name:   "scenario description 2",
			param1: <value1>,
			param2: <value2>,
		},
		// Add more benchmark cases
	}

	for _, bm := range benchmarks {
		b.Run(bm.name, func(b *testing.B) {
			// Arrange
			// Setup code here (automatically excluded from timing by b.Loop)

			// Act
			for b.Loop() {
				_, _ = <Function>(bm.param1, bm.param2)
			}
		})
	}
}

6.2. Simple Benchmarks

For benchmarking a single scenario, use a simple loop without sub-benchmarks.

func Benchmark<FunctionName>(b *testing.B) {
	// Arrange
	// Setup code here (automatically excluded from timing by b.Loop)
	param1 := <value1>
	param2 := <value2>

	// Act
	for b.Loop() {
		_, _ = <Function>(param1, param2)
	}
}

6.3. Benchmarks with Validation

For benchmarks that need to prevent compiler optimizations, store results in package-level variables.

var (
	benchResult <type>
	benchError  error
)

func Benchmark<FunctionName>(b *testing.B) {
	// Arrange
	// Setup code here (automatically excluded from timing by b.Loop)
	param1 := <value1>
	param2 := <value2>

	// Act
	for b.Loop() {
		benchResult, benchError = <Function>(param1, param2)
	}
}

7. References

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.05%
按下载量换算23

Claude

27.51%
按下载量换算18

Cursor

18.58%
按下载量换算12

Gemini CLI

8.56%
按下载量换算6

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills