MCPcopy
hub / github.com/syncthing/syncthing / BenchmarkUpdate

Function BenchmarkUpdate

internal/db/sqlite/db_bench_test.go:24–225  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

22var globalFi protocol.FileInfo
23
24func BenchmarkUpdate(b *testing.B) {
25 db, err := Open(b.TempDir())
26 if err != nil {
27 b.Fatal(err)
28 }
29 b.Cleanup(func() {
30 if err := db.Close(); err != nil {
31 b.Fatal(err)
32 }
33 })
34
35 fs := make([]protocol.FileInfo, 100)
36 t0 := time.Now()
37
38 seed := 0
39 size := 1000
40 const numBlocks = 500
41
42 fdb, err := db.getFolderDB(folderID, true)
43 if err != nil {
44 b.Fatal(err)
45 }
46
47 for size < 200_000 {
48 for {
49 local, err := db.CountLocal(folderID, protocol.LocalDeviceID)
50 if err != nil {
51 b.Fatal(err)
52 }
53 if local.Files >= size {
54 break
55 }
56 fs := make([]protocol.FileInfo, 1000)
57 for i := range fs {
58 fs[i] = genFile(rand.String(24), numBlocks, 0)
59 }
60 if err := db.Update(folderID, protocol.LocalDeviceID, fs); err != nil {
61 b.Fatal(err)
62 }
63 }
64
65 var files, blocks int
66 if err := fdb.sql.QueryRowx(`SELECT count(*) FROM files`).Scan(&files); err != nil {
67 b.Fatal(err)
68 }
69 if err := fdb.sql.QueryRowx(`SELECT count(*) FROM blocks`).Scan(&blocks); err != nil {
70 b.Fatal(err)
71 }
72
73 d := time.Since(t0)
74 b.Logf("t=%s, files=%d, blocks=%d, files/s=%.01f, blocks/s=%.01f", d, files, blocks, float64(files)/d.Seconds(), float64(blocks)/d.Seconds())
75
76 b.Run(fmt.Sprintf("n=Insert100Loc/size=%d", size), func(b *testing.B) {
77 for range b.N {
78 for i := range fs {
79 fs[i] = genFile(rand.String(24), numBlocks, 0)
80 }
81 if err := db.Update(folderID, protocol.LocalDeviceID, fs); err != nil {

Callers

nothing calls this directly

Calls 15

StringFunction · 0.92
StrictlyMonotonicNanosFunction · 0.92
OpenFunction · 0.85
genFileFunction · 0.85
genBlocksFunction · 0.85
FatalMethod · 0.80
getFolderDBMethod · 0.80
CloseMethod · 0.65
NowMethod · 0.65
CountLocalMethod · 0.65
UpdateMethod · 0.65
ScanMethod · 0.65

Tested by

no test coverage detected