]> Cypherpunks repositories - gostls13.git/commitdiff
strconv: run garbage collection before counting allocations in test
authorRuss Cox <rsc@golang.org>
Mon, 20 Feb 2012 03:13:04 +0000 (22:13 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 20 Feb 2012 03:13:04 +0000 (22:13 -0500)
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

src/pkg/strconv/itoa_test.go

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