]> Sergey Matveev's repositories - btrtrc.git/blobdiff - undirtied-chunks-iter_test.go
Drop support for go 1.20
[btrtrc.git] / undirtied-chunks-iter_test.go
index d9b12df4bf31d885a348c699e429eb403bf9d927..9ee6ecf402f41268a76035708e2c639163e11e89 100644 (file)
@@ -3,20 +3,17 @@ package torrent
 import (
        "testing"
 
-       "github.com/RoaringBitmap/roaring"
+       typedRoaring "github.com/anacrolix/torrent/typed-roaring"
 )
 
-func BenchmarkUndirtiedChunksIter(b *testing.B) {
-       var bitmap roaring.Bitmap
-       a := undirtiedChunksIter{
-               TorrentDirtyChunks: &bitmap,
-               StartRequestIndex:  69,
-               EndRequestIndex:    420,
-       }
+func BenchmarkIterUndirtiedRequestIndexesInPiece(b *testing.B) {
+       var bitmap typedRoaring.Bitmap[RequestIndex]
+       it := bitmap.IteratorType()
        b.ReportAllocs()
        for i := 0; i < b.N; i++ {
-               a.Iter(func(chunkIndex chunkIndexType) {
-
-               })
+               // This is the worst case, when Torrent.iterUndirtiedRequestIndexesInPiece can't find a
+               // usable cached iterator. This should be the only allocation.
+               it.Initialize(&bitmap)
+               iterBitmapUnsetInRange(&it, 69, 420, func(RequestIndex) {})
        }
 }