drui0508 2015-05-12 22:34
浏览 54
已采纳

如何在Go中编写基准测试脚本以衡量运营/秒

I am practicing my Golang by writing a simple Redis clone.

How do i write a benchmark script that would establish X connections per second at C concurrency level to deal with my server's protocol and measure how many ops/sec?

I can simply write a script that would actually do this:

for i := range(1000) {
    // Open connection
    // Perform command
    // Close connection
}

But i want to know the concept behind distributing the number of connections per concurrency level per second.

  • 写回答

1条回答 默认 最新

  • dpl9717 2015-05-12 22:43
    关注

    This is best handled by the built-in testing.Benchmark system. For example, a test case like:

    func BenchmarkHello(b *testing.B) {
        for i := 0; i < b.N; i++ {
            fmt.Sprintf("hello")
        }
    }
    

    will automatically work out timing calculations for this function. See the package documentation for more details on setting it up, but it should be very familiar if you've written Go test cases before.

    To your question about concurrency benchmarking, see the RunParallel helper, which is specifically to assist in this.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,
  • ¥15 spaceclaim模型变灰色