diff options
author | Dave Cheney <dave@cheney.net> | 2012-04-14 21:34:08 +1000 |
---|---|---|
committer | Dave Cheney <dave@cheney.net> | 2012-04-14 21:34:08 +1000 |
commit | a502316cdf16f035d5e2af7e5866d55bcc6b3942 (patch) | |
tree | 64dde713e1b9094b6c1b1688ad80b59e95739319 /src/pkg/strconv/itoa_test.go | |
parent | 4eb046ac042dffcb184bd67735080e85de6220c3 (diff) | |
download | go-a502316cdf16f035d5e2af7e5866d55bcc6b3942.tar.gz |
strconv: make malloc tests more reliable
Fixes issue 3495.
I adapted fmt.TestCountMallocs to fix the
existing tests. As the resulting tests did not
appear to belong to either itoa or ftoa I moved
them into their own file.
R=bradfitz, fullung
CC=golang-dev
http://codereview.appspot.com/5985072
Diffstat (limited to 'src/pkg/strconv/itoa_test.go')
-rw-r--r-- | src/pkg/strconv/itoa_test.go | 30 |
1 files changed, 0 insertions, 30 deletions
diff --git a/src/pkg/strconv/itoa_test.go b/src/pkg/strconv/itoa_test.go index 1486ee214..e0213ae9a 100644 --- a/src/pkg/strconv/itoa_test.go +++ b/src/pkg/strconv/itoa_test.go @@ -5,7 +5,6 @@ package strconv_test import ( - "runtime" . "strconv" "testing" ) @@ -126,35 +125,6 @@ func TestUitoa(t *testing.T) { } } -func numAllocations(f func()) int { - runtime.GC() - memstats := new(runtime.MemStats) - runtime.ReadMemStats(memstats) - n0 := memstats.Mallocs - f() - runtime.ReadMemStats(memstats) - return int(memstats.Mallocs - n0) -} - -var globalBuf [64]byte - -func TestAppendUintDoesntAllocate(t *testing.T) { - n := numAllocations(func() { - var buf [64]byte - AppendInt(buf[:0], 123, 10) - }) - want := 1 // TODO(bradfitz): this might be 0, once escape analysis is better - if n != want { - t.Errorf("with local buffer, did %d allocations, want %d", n, want) - } - n = numAllocations(func() { - AppendInt(globalBuf[:0], 123, 10) - }) - if n != 0 { - t.Errorf("with reused buffer, did %d allocations, want 0", n) - } -} - func BenchmarkFormatInt(b *testing.B) { for i := 0; i < b.N; i++ { for _, test := range itob64tests { |