]> Cypherpunks repositories - gostls13.git/commitdiff
fmt: call UpdateMemStats in malloc counter
authorRob Pike <r@golang.org>
Thu, 4 Aug 2011 06:32:14 +0000 (16:32 +1000)
committerRob Pike <r@golang.org>
Thu, 4 Aug 2011 06:32:14 +0000 (16:32 +1000)
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4830059

src/pkg/fmt/fmt_test.go

index d13d09c1b623db9d8e74adff6daf8452d2a8a8ba..1142c9f8ad72ad38754c8e925a4bb375e8cc3169 100644 (file)
@@ -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)
 }