Skip to content

Commit

Permalink
BenchmarkTxn_Get
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov committed May 5, 2024
1 parent b2b0abd commit 498433e
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 2 deletions.
47 changes: 45 additions & 2 deletions mdbx/cursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mdbx

import (
"bytes"
"encoding/binary"
"encoding/hex"
"fmt"
"os"
Expand Down Expand Up @@ -1263,8 +1264,9 @@ func TestCursor_Del_DupSort(t *testing.T) {
if err != nil {
panic(err)
}
fmt.Printf("kk: %s\n", kk)
fmt.Printf("vv: %s\n", vv)
_, _ = kk, vv //TODO: add assert
//fmt.Printf("kk: %s\n", kk)
//fmt.Printf("vv: %s\n", vv)

return nil
})
Expand Down Expand Up @@ -1563,3 +1565,44 @@ func BenchmarkCursor_Renew(b *testing.B) {
return nil
})
}

func BenchmarkCursor_SetRange(b *testing.B) {
env, _ := setup(b)

var db DBI
k := make([]byte, 8)
binary.BigEndian.PutUint64(k, uint64(1))

if err := env.Update(func(txn *Txn) (err error) {
db, err = txn.OpenRoot(0)
if err != nil {
return err
}
err = txn.Put(db, k, k, 0)
if err != nil {
return err
}
return nil
}); err != nil {
b.Errorf("dbi: %v", err)
return
}

if err := env.View(func(txn *Txn) (err error) {
c, err := txn.OpenCursor(db)
if err != nil {
return err
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _, err := c.Get(k, nil, SetRange)
if err != nil {
return err
}
}
return nil
}); err != nil {
b.Errorf("put: %v", err)
}
}
36 changes: 36 additions & 0 deletions mdbx/txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,42 @@ func openDBI(env *Env, key string, flags uint) (DBI, error) {
return db, nil
}

func BenchmarkTxn_Get(b *testing.B) {
env, _ := setup(b)

var db DBI
k := make([]byte, 8)
binary.BigEndian.PutUint64(k, uint64(1))

if err := env.Update(func(txn *Txn) (err error) {
db, err = txn.OpenRoot(0)
if err != nil {
return err
}
err = txn.Put(db, k, k, 0)
if err != nil {
return err
}
return nil
}); err != nil {
b.Errorf("dbi: %v", err)
return
}

if err := env.View(func(txn *Txn) (err error) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := txn.Get(db, k)
if err != nil {
return err
}
}
return nil
}); err != nil {
b.Errorf("put: %v", err)
}
}

func TestTxnEnvWarmup(t *testing.T) {
env, _ := setup(t)

Expand Down

0 comments on commit 498433e

Please sign in to comment.