douqiandai4327 2016-02-23 21:24
浏览 921
已采纳

Go基准测试中的alloc / op和B / op是什么意思?

When I run my benchmarks with go test -v -bench=. -benchmem, I see the following results.

f1     10000        120860 ns/op        2433 B/op         28 allocs/op
f2     10000        120288 ns/op        2288 B/op         26 allocs/op

Based on my understanding:

  1. 10000 is the number of iterations for i := 0; i < b.N; i++ {.
  2. XXX ns/op is approximate time it took for one iteration to complete

But even after reading the docs, I can not find out what B/op and allocs/op mean.


My guess is that allocs/op has something to do with garbage collection and memory allocation (the less the better).

Can anyone give a nice explanation of the meaning of these values. Also it would be nice to know why do the go up and main steps to reduce them (I realize this is test specific, but may be there are some universal hints that work in many cases)

  • 写回答

1条回答 默认 最新

  • dongpao1926 2016-02-23 21:36
    关注

    allocs/op means how many distinct memory allocations occurred per op (single iteration).

    B/op is how many bytes were allocated per op.

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

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境