diff options
| author | Kyle Lemons <kyle@kylelemons.net> | 2013-02-02 22:52:29 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2013-02-02 22:52:29 -0500 |
| commit | 9bfd3c393716d70038788bac102518b901b0d209 (patch) | |
| tree | 1004dda9d550a56c492ebf2ebcc41c7ffeca9813 /src/pkg/path/filepath | |
| parent | f418c505d0b3b9de226f5c28c2345f00299845fc (diff) | |
| download | go-9bfd3c393716d70038788bac102518b901b0d209.tar.xz | |
testing: add AllocsPerRun
This CL also replaces similar loops in other stdlib
package tests with calls to AllocsPerRun.
Fixes #4461.
R=minux.ma, rsc
CC=golang-dev
https://golang.org/cl/7002055
Diffstat (limited to 'src/pkg/path/filepath')
| -rw-r--r-- | src/pkg/path/filepath/path_test.go | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/src/pkg/path/filepath/path_test.go b/src/pkg/path/filepath/path_test.go index bd251a4ebb..84609c4bfc 100644 --- a/src/pkg/path/filepath/path_test.go +++ b/src/pkg/path/filepath/path_test.go @@ -91,7 +91,6 @@ var wincleantests = []PathTest{ } func TestClean(t *testing.T) { - defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(1)) tests := cleantests if runtime.GOOS == "windows" { for i := range tests { @@ -108,20 +107,12 @@ func TestClean(t *testing.T) { } } - var ms runtime.MemStats - runtime.ReadMemStats(&ms) - allocs := -ms.Mallocs - const rounds = 100 - for i := 0; i < rounds; i++ { - for _, test := range tests { - filepath.Clean(test.result) + for _, test := range tests { + allocs := testing.AllocsPerRun(100, func() { filepath.Clean(test.result) }) + if allocs > 0 { + t.Errorf("Clean(%q): %v allocs, want zero", test.result, allocs) } } - runtime.ReadMemStats(&ms) - allocs += ms.Mallocs - if allocs >= rounds { - t.Errorf("Clean cleaned paths: %d allocations per test round, want zero", allocs/rounds) - } } const sep = filepath.Separator |
