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

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.

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

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line