Bench 是一个通用的延迟基准库。它有简单的界面,可以测试各种系统。Bench 每秒发出固定频率的请求,并且同步测量每个请求的延迟。延迟通过 [HDR Histogram](https://github.com/codahale/hdrhistogram) 捕捉,它可以观察整个延迟,并校正 [Coordinated Omission](https://groups.google.com/forum/#%21msg/mechanical-sympathy/icNZJejUHfE/BfDekfBEs_sJ)。Bench 提供一些基本工具,可以将输出绘制出如下面这样的图:
![image](http://static.oschina.net/uploads/space/2015/1223/142718_yEhU_2306979.png)
示例代码:
<pre class="brush:cpp ;toolbar: true; auto-links: false;">package mainimport ( "fmt"
"time"
"github.com/tylertreat/bench"
"github.com/tylertreat/bench/requester")func main() { r := &requester.RedisPubSubRequester{
URL: ":6379",
PayloadSize: 500,
Channel: "benchmark",
} benchmark := bench.NewBenchmark(r, 10000, 30*time.Second)
summary, err := benchmark.Run()
if err != nil { panic(err)
}
fmt.Println(summary)
summary.GenerateLatencyDistribution(bench.Logarithmic, "redis.txt")
}</pre>