Benchmark for single database update
This commit is contained in:
parent
0ce45c20b8
commit
79680b1d5e
|
@ -9,6 +9,7 @@ package db_test
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -620,3 +621,34 @@ func TestLongPath(t *testing.T) {
|
||||||
gf[0].Name, local[0].Name)
|
gf[0].Name, local[0].Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkUpdateOneFile(b *testing.B) {
|
||||||
|
local0 := fileList{
|
||||||
|
protocol.FileInfo{Name: "a", Version: protocol.Vector{{ID: myID, Value: 1000}}, Blocks: genBlocks(1)},
|
||||||
|
protocol.FileInfo{Name: "b", Version: protocol.Vector{{ID: myID, Value: 1000}}, Blocks: genBlocks(2)},
|
||||||
|
protocol.FileInfo{Name: "c", Version: protocol.Vector{{ID: myID, Value: 1000}}, Blocks: genBlocks(3)},
|
||||||
|
protocol.FileInfo{Name: "d", Version: protocol.Vector{{ID: myID, Value: 1000}}, Blocks: genBlocks(4)},
|
||||||
|
// A longer name is more realistic and causes more allocations
|
||||||
|
protocol.FileInfo{Name: "zajksdhaskjdh/askjdhaskjdashkajshd/kasjdhaskjdhaskdjhaskdjash/dkjashdaksjdhaskdjahskdjh", Version: protocol.Vector{{ID: myID, Value: 1000}}, Blocks: genBlocks(8)},
|
||||||
|
}
|
||||||
|
|
||||||
|
ldb, err := db.Open("testdata/benchmarkupdate.db")
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
ldb.Close()
|
||||||
|
os.RemoveAll("testdata/benchmarkupdate.db")
|
||||||
|
}()
|
||||||
|
|
||||||
|
m := db.NewFileSet("test", ldb)
|
||||||
|
m.Replace(protocol.LocalDeviceID, local0)
|
||||||
|
l := local0[4:5]
|
||||||
|
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
l[0].Version = l[0].Version.Update(myID)
|
||||||
|
m.Update(protocol.LocalDeviceID, local0)
|
||||||
|
}
|
||||||
|
|
||||||
|
b.ReportAllocs()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue