diff options
Diffstat (limited to 'libgo/go/strconv/strconv_test.go')
-rw-r--r-- | libgo/go/strconv/strconv_test.go | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/libgo/go/strconv/strconv_test.go b/libgo/go/strconv/strconv_test.go index b01aff1..381874b 100644 --- a/libgo/go/strconv/strconv_test.go +++ b/libgo/go/strconv/strconv_test.go @@ -24,14 +24,12 @@ var ( desc string fn func() }{ - // TODO(bradfitz): this might be 0, once escape analysis is better - {1, `AppendInt(localBuf[:0], 123, 10)`, func() { + {0, `AppendInt(localBuf[:0], 123, 10)`, func() { var localBuf [64]byte AppendInt(localBuf[:0], 123, 10) }}, {0, `AppendInt(globalBuf[:0], 123, 10)`, func() { AppendInt(globalBuf[:0], 123, 10) }}, - // TODO(bradfitz): this might be 0, once escape analysis is better - {1, `AppendFloat(localBuf[:0], 1.23, 'g', 5, 64)`, func() { + {0, `AppendFloat(localBuf[:0], 1.23, 'g', 5, 64)`, func() { var localBuf [64]byte AppendFloat(localBuf[:0], 1.23, 'g', 5, 64) }}, @@ -48,19 +46,13 @@ var ( ) func TestCountMallocs(t *testing.T) { - defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(1)) + if runtime.GOMAXPROCS(0) > 1 { + t.Skip("skipping; GOMAXPROCS>1") + } for _, mt := range mallocTest { - const N = 100 - memstats := new(runtime.MemStats) - runtime.ReadMemStats(memstats) - mallocs := 0 - memstats.Mallocs - for i := 0; i < N; i++ { - mt.fn() - } - runtime.ReadMemStats(memstats) - mallocs += memstats.Mallocs - if mallocs/N > uint64(mt.count) { - t.Errorf("%s: expected %d mallocs, got %d", mt.desc, mt.count, mallocs/N) + allocs := testing.AllocsPerRun(100, mt.fn) + if max := float64(mt.count); allocs > max { + t.Errorf("%s: %v allocs, want <=%v", mt.desc, allocs, max) } } } |