13 _ "github.com/anacrolix/envpprof"
14 "github.com/anacrolix/squirrel"
15 "github.com/anacrolix/torrent/storage"
16 test_storage "github.com/anacrolix/torrent/storage/test"
17 "github.com/dustin/go-humanize"
18 qt "github.com/frankban/quicktest"
21 func BenchmarkMarkComplete(b *testing.B) {
22 const pieceSize = test_storage.DefaultPieceSize
23 const noTriggers = false
24 const noCacheBlobs = false
25 var capacity int64 = test_storage.DefaultNumPieces * pieceSize / 2
27 // Since we won't push out old pieces, we have to mark them incomplete manually.
30 runBench := func(b *testing.B, ci storage.ClientImpl) {
31 test_storage.BenchmarkPieceMarkComplete(b, ci, pieceSize, test_storage.DefaultNumPieces, capacity)
34 b.Run("CustomDirect", func(b *testing.B) {
35 var opts squirrel.NewCacheOpts
36 opts.Capacity = capacity
37 opts.NoTriggers = noTriggers
38 opts.NoCacheBlobs = noCacheBlobs
39 benchOpts := func(b *testing.B) {
40 opts.Path = filepath.Join(b.TempDir(), "storage.db")
41 ci, err := NewDirectStorage(opts)
42 c.Assert(err, qt.IsNil)
46 b.Run("Default", benchOpts)
48 for _, memory := range []bool{false, true} {
49 b.Run(fmt.Sprintf("Memory=%v", memory), func(b *testing.B) {
50 b.Run("Direct", func(b *testing.B) {
51 var opts NewDirectStorageOpts
53 opts.Capacity = capacity
54 // opts.GcBlobs = true
55 opts.BlobFlushInterval = time.Second
56 opts.NoTriggers = noTriggers
57 opts.NoCacheBlobs = noCacheBlobs
58 directBench := func(b *testing.B) {
59 opts.Path = filepath.Join(b.TempDir(), "storage.db")
60 ci, err := NewDirectStorage(opts)
61 var ujm squirrel.ErrUnexpectedJournalMode
62 if errors.As(err, &ujm) {
63 b.Skipf("setting journal mode %q: %v", opts.SetJournalMode, err)
65 c.Assert(err, qt.IsNil)
69 for _, journalMode := range []string{"", "wal", "off", "truncate", "delete", "persist", "memory"} {
70 opts.SetJournalMode = journalMode
71 b.Run("JournalMode="+journalMode, func(b *testing.B) {
72 for _, mmapSize := range []int64{-1} {
73 if memory && mmapSize >= 0 {
76 b.Run(fmt.Sprintf("MmapSize=%s", func() string {
80 return humanize.IBytes(uint64(mmapSize))
82 }()), func(b *testing.B) {
83 opts.MmapSize = mmapSize
84 opts.MmapSizeOk = true