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"
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
23 // Since we won't push out old pieces, we have to mark them incomplete manually.
26 runBench := func(b *testing.B, ci storage.ClientImpl) {
27 test_storage.BenchmarkPieceMarkComplete(b, ci, pieceSize, test_storage.DefaultNumPieces, capacity)
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)
41 b.Run("Default", benchOpts)
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
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)
59 c.Assert(err, qt.IsNil)
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 {
70 b.Run(fmt.Sprintf("MmapSize=%s", func() string {
74 return humanize.IBytes(uint64(mmapSize))
76 }()), func(b *testing.B) {
77 opts.MmapSize = mmapSize
78 opts.MmapSizeOk = true