dgryski / go-perfbook

Thoughts on Go performance optimization

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Testing to ensure upper bound for heap allocations

cobratbq opened this issue · comments

go-perfbook already explains how reducing heap allocations is a way to speed up execution and reduce GC delays, etc. I noticed, through example code from another developer, that it is possible to write tests such that one can effectively ensure a certain bound on heap allocations. This may be helpful for code/libraries that want to ensure/guarantee a low allocation count in specialized libraries, as well as prove that performance does not degrade (without noticing) over time due to changes in own code, Go standard library or run-time.

The test TestAllocations illustrates this.