OLD | NEW |
1 // +build darwin linux | 1 // +build darwin linux |
2 // run | 2 // run |
3 | 3 |
4 // Copyright 2013 The Go Authors. All rights reserved. | 4 // Copyright 2013 The Go Authors. All rights reserved. |
5 // Use of this source code is governed by a BSD-style | 5 // Use of this source code is governed by a BSD-style |
6 // license that can be found in the LICENSE file. | 6 // license that can be found in the LICENSE file. |
7 | 7 |
8 // Test that maps don't go quadratic for NaNs and other values. | 8 // Test that maps don't go quadratic for NaNs and other values. |
9 | 9 |
10 package main | 10 package main |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 133 } |
134 }) | 134 }) |
135 | 135 |
136 // ~32ms on a 1.6GHz Zeon. | 136 // ~32ms on a 1.6GHz Zeon. |
137 checkLinear("complex128", 10000, func(n int) { | 137 checkLinear("complex128", 10000, func(n int) { |
138 m := map[complex128]int{} | 138 m := map[complex128]int{} |
139 for i := 0; i < n; i++ { | 139 for i := 0; i < n; i++ { |
140 m[complex(float64(i), float64(i))] = 1 | 140 m[complex(float64(i), float64(i))] = 1 |
141 } | 141 } |
142 }) | 142 }) |
| 143 |
| 144 // ~70ms on a 1.6GHz Zeon. |
| 145 // The iterate/delete idiom currently takes expected |
| 146 // O(n lg n) time. Fortunately, the checkLinear test |
| 147 // leaves enough wiggle room to include n lg n time |
| 148 // (it actually tests for O(n^log_2(3)). |
| 149 // To prevent false positives, average away variation |
| 150 // by doing multiple rounds within a single run. |
| 151 checkLinear("iterdelete", 2500, func(n int) { |
| 152 for round := 0; round < 4; round++ { |
| 153 m := map[int]int{} |
| 154 for i := 0; i < n; i++ { |
| 155 m[i] = i |
| 156 } |
| 157 for i := 0; i < n; i++ { |
| 158 for k := range m { |
| 159 delete(m, k) |
| 160 break |
| 161 } |
| 162 } |
| 163 } |
| 164 }) |
143 } | 165 } |
OLD | NEW |