]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Use BenchmarkMarkComplete for non-sqlite storages too
authorMatt Joiner <anacrolix@gmail.com>
Wed, 28 Apr 2021 04:46:47 +0000 (14:46 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 4 May 2021 02:44:51 +0000 (12:44 +1000)
storage/mark-complete_test.go [new file with mode: 0644]
storage/sqlite/sqlite-storage_test.go
storage/test/bench-resource-pieces.go

diff --git a/storage/mark-complete_test.go b/storage/mark-complete_test.go
new file mode 100644 (file)
index 0000000..3f76f69
--- /dev/null
@@ -0,0 +1,30 @@
+package storage_test
+
+import (
+       "testing"
+
+       "github.com/anacrolix/torrent/storage"
+       test_storage "github.com/anacrolix/torrent/storage/test"
+)
+
+func BenchmarkMarkComplete(b *testing.B) {
+       bench := func(b *testing.B, ci storage.ClientImpl) {
+               test_storage.BenchmarkPieceMarkComplete(
+                       b, ci, test_storage.DefaultPieceSize, test_storage.DefaultNumPieces, test_storage.DefaultCapacity)
+       }
+       b.Run("File", func(b *testing.B) {
+               ci := storage.NewFile(b.TempDir())
+               b.Cleanup(func() { ci.Close() })
+               bench(b, ci)
+       })
+       b.Run("Mmap", func(b *testing.B) {
+               ci := storage.NewMMap(b.TempDir())
+               b.Cleanup(func() { ci.Close() })
+               bench(b, ci)
+       })
+       b.Run("BoltDb", func(b *testing.B) {
+               ci := storage.NewBoltDB(b.TempDir())
+               b.Cleanup(func() { ci.Close() })
+               bench(b, ci)
+       })
+}
index 3f599d5169278051b8da00f591151ad3e18cb177..a903e3a9c5bd37b3093952b39810199dddec27b1 100644 (file)
@@ -67,8 +67,8 @@ func TestSimultaneousIncrementalBlob(t *testing.T) {
 }
 
 func BenchmarkMarkComplete(b *testing.B) {
-       const pieceSize = 2 << 20
-       const capacity = 0
+       const pieceSize = test_storage.DefaultPieceSize
+       const capacity = test_storage.DefaultCapacity
        c := qt.New(b)
        for _, memory := range []bool{false, true} {
                b.Run(fmt.Sprintf("Memory=%v", memory), func(b *testing.B) {
@@ -90,7 +90,7 @@ func BenchmarkMarkComplete(b *testing.B) {
                                        })
                                        c.Assert(err, qt.IsNil)
                                        defer ci.Close()
-                                       test_storage.BenchmarkPieceMarkComplete(b, ci, pieceSize, 16, capacity)
+                                       test_storage.BenchmarkPieceMarkComplete(b, ci, pieceSize, test_storage.DefaultNumPieces, capacity)
                                })
                        }
                })
index 9564648400bf33adf77ed8a93bb5ad77bb0a9c9f..4a79c313c2acd45674aa5890efa31b437248ba0f 100644 (file)
@@ -14,37 +14,47 @@ import (
        qt "github.com/frankban/quicktest"
 )
 
-const chunkSize = 1 << 14
+const (
+       ChunkSize        = 1 << 14
+       DefaultPieceSize = 2 << 20
+       DefaultCapacity  = 0
+       DefaultNumPieces = 16
+)
 
-func BenchmarkPieceMarkComplete(b *testing.B, ci storage.ClientImpl, pieceSize int64, numPieces int, capacity int64) {
+func BenchmarkPieceMarkComplete(
+       b *testing.B, ci storage.ClientImpl,
+       pieceSize int64, numPieces int, capacity int64,
+) {
+       const check = true
        c := qt.New(b)
-       ti, err := ci.OpenTorrent(&metainfo.Info{
-               Pieces:      make([]byte, metainfo.HashSize*numPieces),
-               PieceLength: pieceSize,
-       }, metainfo.Hash{})
-       c.Assert(err, qt.IsNil)
-       defer ti.Close()
        info := &metainfo.Info{
                Pieces:      make([]byte, numPieces*metainfo.HashSize),
                PieceLength: pieceSize,
                Length:      pieceSize * int64(numPieces),
+               Name:        "TorrentName",
        }
+       ti, err := ci.OpenTorrent(info, metainfo.Hash{})
+       c.Assert(err, qt.IsNil)
+       defer ti.Close()
        rand.Read(info.Pieces)
        data := make([]byte, pieceSize)
+       b.SetBytes(int64(numPieces) * pieceSize)
        oneIter := func() {
                for pieceIndex := range iter.N(numPieces) {
                        pi := ti.Piece(info.Piece(pieceIndex))
-                       rand.Read(data)
+                       if check {
+                               rand.Read(data)
+                       }
                        var wg sync.WaitGroup
-                       for off := int64(0); off < int64(len(data)); off += chunkSize {
+                       for off := int64(0); off < int64(len(data)); off += ChunkSize {
                                wg.Add(1)
                                go func(off int64) {
                                        defer wg.Done()
-                                       n, err := pi.WriteAt(data[off:off+chunkSize], off)
+                                       n, err := pi.WriteAt(data[off:off+ChunkSize], off)
                                        if err != nil {
                                                panic(err)
                                        }
-                                       if n != chunkSize {
+                                       if n != ChunkSize {
                                                panic(n)
                                        }
                                }(off)
@@ -57,10 +67,12 @@ func BenchmarkPieceMarkComplete(b *testing.B, ci storage.ClientImpl, pieceSize i
                        c.Assert(pi.Completion(), qt.Equals, storage.Completion{Complete: false, Ok: true})
                        c.Assert(pi.MarkComplete(), qt.IsNil)
                        c.Assert(pi.Completion(), qt.Equals, storage.Completion{true, true})
-                       readData, err := ioutil.ReadAll(io.NewSectionReader(pi, 0, int64(len(data))))
-                       c.Assert(err, qt.IsNil)
-                       c.Assert(len(readData), qt.Equals, len(data))
-                       c.Assert(bytes.Equal(readData, data), qt.IsTrue)
+                       if check {
+                               readData, err := ioutil.ReadAll(io.NewSectionReader(pi, 0, int64(len(data))))
+                               c.Assert(err, qt.IsNil)
+                               c.Assert(len(readData), qt.Equals, len(data))
+                               c.Assert(bytes.Equal(readData, data), qt.IsTrue)
+                       }
                }
        }
        // Fill the cache