| 2335 | } |
| 2336 | |
| 2337 | func BenchmarkSortedMap_Iterator(b *testing.B) { |
| 2338 | const n = 10000 |
| 2339 | m := NewSortedMap[int, int](nil) |
| 2340 | for i := 0; i < 10000; i++ { |
| 2341 | m = m.Set(i, i) |
| 2342 | } |
| 2343 | b.ReportAllocs() |
| 2344 | b.ResetTimer() |
| 2345 | |
| 2346 | b.Run("Forward", func(b *testing.B) { |
| 2347 | itr := m.Iterator() |
| 2348 | for i := 0; i < b.N; i++ { |
| 2349 | if i%n == 0 { |
| 2350 | itr.First() |
| 2351 | } |
| 2352 | itr.Next() |
| 2353 | } |
| 2354 | }) |
| 2355 | |
| 2356 | b.Run("Reverse", func(b *testing.B) { |
| 2357 | itr := m.Iterator() |
| 2358 | for i := 0; i < b.N; i++ { |
| 2359 | if i%n == 0 { |
| 2360 | itr.Last() |
| 2361 | } |
| 2362 | itr.Prev() |
| 2363 | } |
| 2364 | }) |
| 2365 | } |
| 2366 | |
| 2367 | func BenchmarkSortedMapBuilder_Set(b *testing.B) { |
| 2368 | b.ReportAllocs() |