Golang Benchmark Test

内部程序是CPU密集型计算,因此编写了 Benchmark 测试算子的性能,并且希望在此基础上,将 Benchmark 在各服务器上执行,验证服务器性能情况。

Benchmark 编译

go test -c -test.bench=".*" ./filter/

执行后将在本地生成 filter.test

Benchmark 运行

首先在目标服务器上将编译好的二进制文件拉取到本地。

./teleport.benchmark-v1 -test.bench=".*" -test.cpu=1 -test.count 5

Golang test 参数详解

Usage of ./filter.test:
  -test.bench regexp
    	run only benchmarks matching regexp
  -test.benchmem
    	print memory allocations for benchmarks
  -test.benchtime d
    	run each benchmark for duration d (default 1s)
  -test.blockprofile file
    	write a goroutine blocking profile to file
  -test.blockprofilerate rate
    	set blocking profile rate (see runtime.SetBlockProfileRate) (default 1)
  -test.count n
    	run tests and benchmarks n times (default 1)
  -test.coverprofile file
    	write a coverage profile to file
  -test.cpu list
    	comma-separated list of cpu counts to run each test with
  -test.cpuprofile file
    	write a cpu profile to file
  -test.failfast
    	do not start new tests after the first test failure
  -test.list regexp
    	list tests, examples, and benchmarks matching regexp then exit
  -test.memprofile file
    	write an allocation profile to file
  -test.memprofilerate rate
    	set memory allocation profiling rate (see runtime.MemProfileRate)
  -test.mutexprofile string
    	write a mutex contention profile to the named file after execution
  -test.mutexprofilefraction int
    	if >= 0, calls runtime.SetMutexProfileFraction() (default 1)
  -test.outputdir dir
    	write profiles to dir
  -test.parallel n
    	run at most n tests in parallel (default 40)
  -test.run regexp
    	run only tests and examples matching regexp
  -test.short
    	run smaller test suite to save time
  -test.testlogfile file
    	write test action log to file (for use only by cmd/go)
  -test.timeout d
    	panic test binary after duration d (default 0, timeout disabled)
  -test.trace file
    	write an execution trace to file
  -test.v
    	verbose: print additional output
参数 说明 使用案例
test.bench 指定需要执行的 Benchmark 方法 -test.bench=“BenchmarkSplit*”
test.benchmem Benchchmark 输出是否包含内存信息 -test.benchmem
test.benchtime 每个 Benchmark 执行的时间 -test.benchtime=2s
test.blockprofile
test.blockprofilerate
test.count 每个 Benchmark 执行的次数 -test.count=2
test.coverprofile
test.cpu 执行 Benchmark 的CPU个数 -test.cpu=1
test.cpuprofile 是否输出cpu性能分析文件
test.failfast
test.list 列出所有符合条件的测试用例
test.memprofile 是否输出内存性能分析文件
test.memprofilerate
test.mutexprofile
test.mutexprofilefraction
test.outputdir
test.parallel
test.run
test.short
test.testlogfile
test.timeout 测试用例超时时间
test.trace
test.v

你可能感兴趣的:(Golang,Linux)