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

Function BenchmarkBucket_CreateBucketIfNotExists

bucket_test.go:1994–2020  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

1992}
1993
1994func BenchmarkBucket_CreateBucketIfNotExists(b *testing.B) {
1995 db := btesting.MustCreateDB(b)
1996 defer db.MustClose()
1997
1998 const bucketCount = 1_000_000
1999
2000 err := db.Update(func(tx *bolt.Tx) error {
2001 for i := 0; i < bucketCount; i++ {
2002 bucketName := fmt.Sprintf("bucket_%d", i)
2003 _, berr := tx.CreateBucket([]byte(bucketName))
2004 require.NoError(b, berr)
2005 }
2006 return nil
2007 })
2008 require.NoError(b, err)
2009
2010 b.ResetTimer()
2011 b.ReportAllocs()
2012
2013 for i := 0; i < b.N; i++ {
2014 err := db.Update(func(tx *bolt.Tx) error {
2015 _, berr := tx.CreateBucketIfNotExists([]byte("bucket_100"))
2016 return berr
2017 })
2018 require.NoError(b, err)
2019 }
2020}
2021
2022func ExampleBucket_Put() {
2023 // Open the database.

Callers

nothing calls this directly

Calls 5

MustCreateDBFunction · 0.92
MustCloseMethod · 0.80
UpdateMethod · 0.80
CreateBucketMethod · 0.45

Tested by

no test coverage detected