diff options
author | Keith Randall <khr@golang.org> | 2014-09-10 22:54:07 -0700 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2014-09-10 22:54:07 -0700 |
commit | c395ef800ee694e3a2ef451010c3f72b0aee4aed (patch) | |
tree | 22af97598394b729ea387696bc4365c0a20ff166 /test | |
parent | 1884fb06321882d59cd9678b6f1f9fcaafdf9a27 (diff) | |
download | go-c395ef800ee694e3a2ef451010c3f72b0aee4aed.tar.gz |
runtime: add timing test for iterate/delete map idiom.
LGTM=bradfitz, iant
R=iant, bradfitz
CC=golang-codereviews
https://codereview.appspot.com/140510043
Diffstat (limited to 'test')
-rw-r--r-- | test/maplinear.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/maplinear.go b/test/maplinear.go index 56e50951a..8cc198b8f 100644 --- a/test/maplinear.go +++ b/test/maplinear.go @@ -140,4 +140,22 @@ func main() { m[complex(float64(i), float64(i))] = 1 } }) + + // ~70ms on a 1.6GHz Zeon. + // The iterate/delete idiom currently takes expected + // O(n lg n) time. Fortunately, the checkLinear test + // leaves enough wiggle room to include n lg n time + // (it actually tests for O(n^log_2(3)). + checkLinear("iterdelete", 10000, func(n int) { + m := map[int]int{} + for i := 0; i < n; i++ { + m[i] = i + } + for i := 0; i < n; i++ { + for k := range m { + delete(m, k) + break + } + } + }) } |