aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/exp
diff options
context:
space:
mode:
authorShenghou Ma <minux.ma@gmail.com>2013-01-17 18:45:49 +0800
committerShenghou Ma <minux.ma@gmail.com>2013-01-17 18:45:49 +0800
commit1e095b76229a8faa329dbdee6de246faabc3cf53 (patch)
treec4e05e9370cfef0ee7135a1afcc7866531595aec /src/pkg/exp
parentf5958c614166e957f2e409aaaf1db30e3c17e794 (diff)
downloadgo-1e095b76229a8faa329dbdee6de246faabc3cf53.tar.xz
testing: introduce (*B).ReportAllocs()
Calling it will show memory allocation statistics for that single benchmark (if -test.benchmem is not provided) R=golang-dev, rsc, kevlar, bradfitz CC=golang-dev https://golang.org/cl/7027046
Diffstat (limited to 'src/pkg/exp')
-rw-r--r--src/pkg/exp/html/parse_test.go8
-rw-r--r--src/pkg/exp/html/token_test.go8
2 files changed, 2 insertions, 14 deletions
diff --git a/src/pkg/exp/html/parse_test.go b/src/pkg/exp/html/parse_test.go
index 7cf2ff4163..4896dfb7a0 100644
--- a/src/pkg/exp/html/parse_test.go
+++ b/src/pkg/exp/html/parse_test.go
@@ -382,15 +382,9 @@ func BenchmarkParser(b *testing.B) {
}
b.SetBytes(int64(len(buf)))
runtime.GC()
- var ms runtime.MemStats
- runtime.ReadMemStats(&ms)
- mallocs := ms.Mallocs
+ b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
Parse(bytes.NewBuffer(buf))
}
- b.StopTimer()
- runtime.ReadMemStats(&ms)
- mallocs = ms.Mallocs - mallocs
- b.Logf("%d iterations, %d mallocs per iteration\n", b.N, int(mallocs)/b.N)
}
diff --git a/src/pkg/exp/html/token_test.go b/src/pkg/exp/html/token_test.go
index 63a8bfc483..14e23467f4 100644
--- a/src/pkg/exp/html/token_test.go
+++ b/src/pkg/exp/html/token_test.go
@@ -634,9 +634,7 @@ func benchmarkTokenizer(b *testing.B, level int) {
}
b.SetBytes(int64(len(buf)))
runtime.GC()
- var ms runtime.MemStats
- runtime.ReadMemStats(&ms)
- mallocs := ms.Mallocs
+ b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
z := NewTokenizer(bytes.NewBuffer(buf))
@@ -674,10 +672,6 @@ func benchmarkTokenizer(b *testing.B, level int) {
}
}
}
- b.StopTimer()
- runtime.ReadMemStats(&ms)
- mallocs = ms.Mallocs - mallocs
- b.Logf("%d iterations, %d mallocs per iteration\n", b.N, int(mallocs)/b.N)
}
func BenchmarkRawLevelTokenizer(b *testing.B) { benchmarkTokenizer(b, rawLevel) }