From: Rob Pike Date: Thu, 4 Aug 2011 06:32:14 +0000 (+1000) Subject: fmt: call UpdateMemStats in malloc counter X-Git-Tag: weekly.2011-08-10~34 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=583f72434f5930bc40177bc9e3bca1a4ee027501;p=gostls13.git fmt: call UpdateMemStats in malloc counter R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/4830059 --- diff --git a/src/pkg/fmt/fmt_test.go b/src/pkg/fmt/fmt_test.go index d13d09c1b6..1142c9f8ad 100644 --- a/src/pkg/fmt/fmt_test.go +++ b/src/pkg/fmt/fmt_test.go @@ -477,28 +477,36 @@ func TestCountMallocs(t *testing.T) { if testing.Short() { return } + runtime.UpdateMemStats() mallocs := 0 - runtime.MemStats.Mallocs for i := 0; i < 100; i++ { Sprintf("") } + runtime.UpdateMemStats() mallocs += runtime.MemStats.Mallocs Printf("mallocs per Sprintf(\"\"): %d\n", mallocs/100) + runtime.UpdateMemStats() mallocs = 0 - runtime.MemStats.Mallocs for i := 0; i < 100; i++ { Sprintf("xxx") } + runtime.UpdateMemStats() mallocs += runtime.MemStats.Mallocs Printf("mallocs per Sprintf(\"xxx\"): %d\n", mallocs/100) + runtime.UpdateMemStats() mallocs = 0 - runtime.MemStats.Mallocs for i := 0; i < 100; i++ { Sprintf("%x", i) } + runtime.UpdateMemStats() mallocs += runtime.MemStats.Mallocs Printf("mallocs per Sprintf(\"%%x\"): %d\n", mallocs/100) + runtime.UpdateMemStats() mallocs = 0 - runtime.MemStats.Mallocs for i := 0; i < 100; i++ { Sprintf("%x %x", i, i) } + runtime.UpdateMemStats() mallocs += runtime.MemStats.Mallocs Printf("mallocs per Sprintf(\"%%x %%x\"): %d\n", mallocs/100) }