(b *testing.B)
| 2030 | } |
| 2031 | |
| 2032 | func 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 | |
| 2077 | func BenchmarkDBBatchSingle(b *testing.B) { |
| 2078 | db := btesting.MustCreateDB(b) |
nothing calls this directly
no test coverage detected