1
0
mirror of https://github.com/golang/go synced 2024-11-22 05:14:40 -07:00

strconv: run garbage collection before counting allocations in test

My theory is that the call to f() allocates, which triggers
a garbage collection, which itself may do some allocation,
which is being counted.  Running a garbage collection
before starting the test should avoid this problem.

Fixes #2894 (I hope).

R=golang-dev, bradfitz, nigeltao
CC=golang-dev
https://golang.org/cl/5685046
This commit is contained in:
Russ Cox 2012-02-19 22:13:04 -05:00
parent 9c9b96f028
commit a53317668a

View File

@ -127,6 +127,7 @@ func TestUitoa(t *testing.T) {
} }
func numAllocations(f func()) int { func numAllocations(f func()) int {
runtime.GC()
memstats := new(runtime.MemStats) memstats := new(runtime.MemStats)
runtime.ReadMemStats(memstats) runtime.ReadMemStats(memstats)
n0 := memstats.Mallocs n0 := memstats.Mallocs