MCPcopy
hub / github.com/etcd-io/bbolt / BenchmarkDBBatchSingle

Function BenchmarkDBBatchSingle

db_test.go:2077–2118  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

2075}
2076
2077func BenchmarkDBBatchSingle(b *testing.B) {
2078 db := btesting.MustCreateDB(b)
2079 if err := db.Update(func(tx *bolt.Tx) error {
2080 _, err := tx.CreateBucket([]byte("bench"))
2081 return err
2082 }); err != nil {
2083 b.Fatal(err)
2084 }
2085
2086 b.ResetTimer()
2087 for i := 0; i < b.N; i++ {
2088 start := make(chan struct{})
2089 var wg sync.WaitGroup
2090
2091 for round := 0; round < 1000; round++ {
2092 wg.Add(1)
2093 go func(id uint32) {
2094 defer wg.Done()
2095 <-start
2096
2097 h := fnv.New32a()
2098 buf := make([]byte, 4)
2099 binary.LittleEndian.PutUint32(buf, id)
2100 _, _ = h.Write(buf[:])
2101 k := h.Sum(nil)
2102 insert := func(tx *bolt.Tx) error {
2103 b := tx.Bucket([]byte("bench"))
2104 return b.Put(k, []byte("filler"))
2105 }
2106 if err := db.Update(insert); err != nil {
2107 b.Error(err)
2108 return
2109 }
2110 }(uint32(round))
2111 }
2112 close(start)
2113 wg.Wait()
2114 }
2115
2116 b.StopTimer()
2117 validateBatchBench(b, db)
2118}
2119
2120func BenchmarkDBBatchManual10x100(b *testing.B) {
2121 db := btesting.MustCreateDB(b)

Callers

nothing calls this directly

Calls 10

MustCreateDBFunction · 0.92
validateBatchBenchFunction · 0.85
UpdateMethod · 0.80
AddMethod · 0.80
FatalMethod · 0.65
WriteMethod · 0.65
ErrorMethod · 0.65
CreateBucketMethod · 0.45
BucketMethod · 0.45
PutMethod · 0.45

Tested by

no test coverage detected