v / cmd / tools / bench / map_clear.v
19 lines · 18 sloc · 380 bytes · 673ac0a411b4d37625e0384903d1a9ca6eb8120b
Raw
1import benchmark
2
3fn main() {
4 max_iterations := arguments()[1] or { '1_000_000' }.int()
5 assert max_iterations > 0
6 mut m := {
7 123: 456
8 789: 321
9 }
10 mut volatile sum := u64(0)
11 mut b := benchmark.start()
12 for i in 0 .. max_iterations {
13 m.clear()
14 m[i] = i * 2
15 sum += u64(m.len)
16 }
17 assert m.len == 1
18 b.measure('m.clear(), iterations: ${max_iterations}, sum: ${sum}')
19}
20