Commit e7fb63c5 authored by Kirill Smelkov's avatar Kirill Smelkov

X benchmarks for Iterate + fstail

parent 2ebe0d64
......@@ -128,6 +128,9 @@ func fsTail(w io.Writer, path string, ntxn int) (err error) {
txnh := fs1.TxnHeader{}
data := []byte{}
// TODO use SeqBufReader instead of f and check speedup
// start iterating at tail.
// this should get EOF but read txnh.LenPrev ok.
err = txnh.Load(f, topPos, fs1.LoadAll)
......
......@@ -29,7 +29,7 @@ func diff(a, b string) string {
return dmp.DiffPrettyText(diffv)
}
func TestFsDump(t *testing.T) {
func TestFsTail(t *testing.T) {
buf := bytes.Buffer{}
err := fsTail(&buf, "../../testdata/1.fs", 1000000)
......@@ -43,3 +43,12 @@ func TestFsDump(t *testing.T) {
t.Errorf("dump different:\n%v", diff(dumpOk, buf.String()))
}
}
func BenchmarkFsTail(b *testing.B) {
for i := 0; i < b.N; i++ {
err := fsTail(ioutil.Discard, "../../testdata/1.fs", 1000000)
if err != nil {
b.Fatal(err)
}
}
}
......@@ -80,7 +80,7 @@ func checkLoad(t *testing.T, fs *FileStorage, xid zodb.Xid, expect oidLoadedOk)
}
}
func xfsopen(t *testing.T, path string) *FileStorage {
func xfsopen(t testing.TB, path string) *FileStorage {
fs, err := Open(path)
if err != nil {
t.Fatal(err)
......@@ -265,3 +265,42 @@ func TestIterate(t *testing.T) {
// also check 0..tidMax
testIterate(t, fs, 0, zodb.TidMax, _1fs_dbEntryv[:])
}
func BenchmarkIterate(b *testing.B) {
fs := xfsopen(b, "testdata/1.fs") // TODO open ro
defer exc.XRun(fs.Close)
b.ResetTimer()
for i := 0; i < b.N; i++ {
iter := fs.Iterate(zodb.Tid(0), zodb.TidMax)
for {
txni, dataIter, err := iter.NextTxn()
if err != nil {
if err == io.EOF {
break
}
b.Fatal(err)
}
// use txni
_ = txni.Tid
for {
datai, err := dataIter.NextData()
if err != nil {
if err == io.EOF {
break
}
b.Fatal(err)
}
// use datai
_ = datai.Data
}
}
}
b.StopTimer()
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment