MCPcopy
hub / github.com/dgraph-io/badger / BenchmarkReadWrite

Function BenchmarkReadWrite

value_test.go:903–966  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

901}
902
903func BenchmarkReadWrite(b *testing.B) {
904 rwRatio := []float32{
905 0.1, 0.2, 0.5, 1.0,
906 }
907 valueSize := []int{
908 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384,
909 }
910
911 for _, vsz := range valueSize {
912 for _, rw := range rwRatio {
913 b.Run(fmt.Sprintf("%3.1f,%04d", rw, vsz), func(b *testing.B) {
914 dir, err := ioutil.TempDir("", "vlog-benchmark")
915 y.Check(err)
916 defer removeDir(dir)
917
918 db, err := Open(getTestOptions(dir))
919 y.Check(err)
920
921 vl := &db.vlog
922 b.ResetTimer()
923
924 for i := 0; i < b.N; i++ {
925 e := new(Entry)
926 e.Key = make([]byte, 16)
927 e.Value = make([]byte, vsz)
928 bl := new(request)
929 bl.Entries = []*Entry{e}
930
931 var ptrs []valuePointer
932
933 vl.write([]*request{bl})
934 ptrs = append(ptrs, bl.Ptrs...)
935
936 f := rand.Float32()
937 if f < rw {
938 vl.write([]*request{bl})
939
940 } else {
941 ln := len(ptrs)
942 if ln == 0 {
943 b.Fatalf("Zero length of ptrs")
944 }
945 idx := rand.Intn(ln)
946 s := new(y.Slice)
947 buf, lf, err := vl.readValueBytes(ptrs[idx], s)
948 if err != nil {
949 b.Fatalf("Benchmark Read: %v", err)
950 }
951
952 e, err := lf.decodeEntry(buf, ptrs[idx].Offset)
953 require.NoError(b, err)
954 if len(e.Key) != 16 {
955 b.Fatalf("Key is invalid")
956 }
957 if len(e.Value) != vsz {
958 b.Fatalf("Value is invalid")
959 }
960 runCallback(db.vlog.getUnlockCallback(lf))

Callers

nothing calls this directly

Calls 9

CheckFunction · 0.92
removeDirFunction · 0.85
OpenFunction · 0.85
getTestOptionsFunction · 0.85
runCallbackFunction · 0.85
readValueBytesMethod · 0.80
decodeEntryMethod · 0.80
getUnlockCallbackMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…