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

Function BenchmarkDBBatchAutomatic

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

Source from the content-addressed store, hash-verified

2030}
2031
2032func BenchmarkDBBatchAutomatic(b *testing.B) {
2033 db := btesting.MustCreateDB(b)
2034
2035 if err := db.Update(func(tx *bolt.Tx) error {
2036 _, err := tx.CreateBucket([]byte("bench"))
2037 return err
2038 }); err != nil {
2039 b.Fatal(err)
2040 }
2041
2042 b.ResetTimer()
2043 for i := 0; i < b.N; i++ {
2044 start := make(chan struct{})
2045 var wg sync.WaitGroup
2046
2047 for round := 0; round < 1000; round++ {
2048 wg.Add(1)
2049
2050 go func(id uint32) {
2051 defer wg.Done()
2052 <-start
2053
2054 h := fnv.New32a()
2055 buf := make([]byte, 4)
2056 binary.LittleEndian.PutUint32(buf, id)
2057 _, _ = h.Write(buf[:])
2058 k := h.Sum(nil)
2059 insert := func(tx *bolt.Tx) error {
2060 b := tx.Bucket([]byte("bench"))
2061 return b.Put(k, []byte("filler"))
2062 }
2063 if err := db.Batch(insert); err != nil {
2064 b.Error(err)
2065 return
2066 }
2067 }(uint32(round))
2068 }
2069 close(start)
2070 wg.Wait()
2071 }
2072
2073 b.StopTimer()
2074 validateBatchBench(b, db)
2075}
2076
2077func BenchmarkDBBatchSingle(b *testing.B) {
2078 db := btesting.MustCreateDB(b)

Callers

nothing calls this directly

Calls 11

MustCreateDBFunction · 0.92
validateBatchBenchFunction · 0.85
UpdateMethod · 0.80
AddMethod · 0.80
BatchMethod · 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