]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add timing test for iterate/delete map idiom.
authorKeith Randall <khr@golang.org>
Thu, 11 Sep 2014 05:54:07 +0000 (22:54 -0700)
committerKeith Randall <khr@golang.org>
Thu, 11 Sep 2014 05:54:07 +0000 (22:54 -0700)
LGTM=bradfitz, iant
R=iant, bradfitz
CC=golang-codereviews
https://golang.org/cl/140510043

test/maplinear.go

index 56e50951af28570b161268cf3f4661aa894b4581..8cc198b8fe443adfa42de286975e9b14ca7c6425 100644 (file)
@@ -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
+                       }
+               }
+       })
 }