本文整理匯總了Golang中testing.B.Cursor方法的典型用法代碼示例。如果您正苦於以下問題:Golang B.Cursor方法的具體用法?Golang B.Cursor怎麽用?Golang B.Cursor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類testing.B
的用法示例。
在下文中一共展示了B.Cursor方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: BenchmarkGetParameters
func BenchmarkGetParameters(b *testing.B) {
group := "testdb"
// generate the fingerprintsInMemory
fingerprintsInMemory := make(map[string]Fingerprint)
var fingerprintsOrdering []string
db, err := bolt.Open(path.Join(RuntimeArgs.SourcePath, group+".db"), 0600, nil)
if err != nil {
log.Fatal(err)
}
db.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("fingerprints"))
c := b.Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
fingerprintsInMemory[string(v)] = loadFingerprint(v)
fingerprintsOrdering = append(fingerprintsOrdering, string(v))
}
return nil
})
db.Close()
var ps = *NewFullParameters()
b.ResetTimer()
for i := 0; i < b.N; i++ {
getParameters(group, &ps, fingerprintsInMemory, fingerprintsOrdering)
}
}
示例2: BenchmarkGetFingerprintInDatabase
func BenchmarkGetFingerprintInDatabase(b *testing.B) {
for i := 0; i < b.N; i++ {
group := "testdb"
db, _ := bolt.Open(path.Join(RuntimeArgs.SourcePath, group+".db"), 0600, nil)
db.View(func(tx *bolt.Tx) error {
// Assume bucket exists and has keys
b := tx.Bucket([]byte("fingerprints"))
c := b.Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
loadFingerprint(v)
break
}
return nil
})
db.Close()
}
}
示例3: BenchmarkCrossValidation
func BenchmarkCrossValidation(b *testing.B) {
group := "testdb"
// generate the fingerprintsInMemory
fingerprintsInMemory := make(map[string]Fingerprint)
var fingerprintsOrdering []string
db, err := bolt.Open(path.Join(RuntimeArgs.SourcePath, group+".db"), 0600, nil)
if err != nil {
log.Fatal(err)
}
db.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("fingerprints"))
c := b.Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
fingerprintsInMemory[string(k)] = loadFingerprint(v)
fingerprintsOrdering = append(fingerprintsOrdering, string(k))
}
return nil
})
db.Close()
var ps = *NewFullParameters()
getParameters(group, &ps, fingerprintsInMemory, fingerprintsOrdering)
calculatePriors(group, &ps, fingerprintsInMemory, fingerprintsOrdering)
var results = *NewResultsParameters()
for n := range ps.Priors {
ps.Results[n] = results
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for n := range ps.Priors {
ps.Priors[n].Special["MixIn"] = 0.5
ps.Priors[n].Special["VarabilityCutoff"] = 0.005
crossValidation(group, n, &ps, fingerprintsInMemory, fingerprintsOrdering)
break
}
}
}