]> Sergey Matveev's repositories - btrtrc.git/blob - storage/sqlite/sqlite-storage_test.go
Remove CGO build flags for pure-Go squirrel branch
[btrtrc.git] / storage / sqlite / sqlite-storage_test.go
1 package sqliteStorage
2
3 import (
4         "errors"
5         "fmt"
6         "path/filepath"
7         "testing"
8         "time"
9
10         _ "github.com/anacrolix/envpprof"
11         "github.com/anacrolix/squirrel"
12         "github.com/anacrolix/torrent/storage"
13         test_storage "github.com/anacrolix/torrent/storage/test"
14         "github.com/dustin/go-humanize"
15         qt "github.com/frankban/quicktest"
16 )
17
18 func BenchmarkMarkComplete(b *testing.B) {
19         const pieceSize = test_storage.DefaultPieceSize
20         const noTriggers = false
21         var capacity int64 = test_storage.DefaultNumPieces * pieceSize / 2
22         if noTriggers {
23                 // Since we won't push out old pieces, we have to mark them incomplete manually.
24                 capacity = 0
25         }
26         runBench := func(b *testing.B, ci storage.ClientImpl) {
27                 test_storage.BenchmarkPieceMarkComplete(b, ci, pieceSize, test_storage.DefaultNumPieces, capacity)
28         }
29         c := qt.New(b)
30         b.Run("CustomDirect", func(b *testing.B) {
31                 var opts squirrel.NewCacheOpts
32                 opts.Capacity = capacity
33                 opts.NoTriggers = noTriggers
34                 benchOpts := func(b *testing.B) {
35                         opts.Path = filepath.Join(b.TempDir(), "storage.db")
36                         ci, err := NewDirectStorage(opts)
37                         c.Assert(err, qt.IsNil)
38                         defer ci.Close()
39                         runBench(b, ci)
40                 }
41                 b.Run("Default", benchOpts)
42         })
43         for _, memory := range []bool{false, true} {
44                 b.Run(fmt.Sprintf("Memory=%v", memory), func(b *testing.B) {
45                         b.Run("Direct", func(b *testing.B) {
46                                 var opts NewDirectStorageOpts
47                                 opts.Memory = memory
48                                 opts.Capacity = capacity
49                                 // opts.GcBlobs = true
50                                 opts.BlobFlushInterval = time.Second
51                                 opts.NoTriggers = noTriggers
52                                 directBench := func(b *testing.B) {
53                                         opts.Path = filepath.Join(b.TempDir(), "storage.db")
54                                         ci, err := NewDirectStorage(opts)
55                                         var ujm squirrel.ErrUnexpectedJournalMode
56                                         if errors.As(err, &ujm) {
57                                                 b.Skipf("setting journal mode %q: %v", opts.SetJournalMode, err)
58                                         }
59                                         c.Assert(err, qt.IsNil)
60                                         defer ci.Close()
61                                         runBench(b, ci)
62                                 }
63                                 for _, journalMode := range []string{"", "wal", "off", "truncate", "delete", "persist", "memory"} {
64                                         opts.SetJournalMode = journalMode
65                                         b.Run("JournalMode="+journalMode, func(b *testing.B) {
66                                                 for _, mmapSize := range []int64{-1} {
67                                                         if memory && mmapSize >= 0 {
68                                                                 continue
69                                                         }
70                                                         b.Run(fmt.Sprintf("MmapSize=%s", func() string {
71                                                                 if mmapSize < 0 {
72                                                                         return "default"
73                                                                 } else {
74                                                                         return humanize.IBytes(uint64(mmapSize))
75                                                                 }
76                                                         }()), func(b *testing.B) {
77                                                                 opts.MmapSize = mmapSize
78                                                                 opts.MmapSizeOk = true
79                                                                 directBench(b)
80                                                         })
81                                                 }
82                                         })
83                                 }
84                         })
85                 })
86         }
87 }