當前位置: 首頁>>代碼示例>>Golang>>正文


Golang B.Get方法代碼示例

本文整理匯總了Golang中testing.B.Get方法的典型用法代碼示例。如果您正苦於以下問題:Golang B.Get方法的具體用法?Golang B.Get怎麽用?Golang B.Get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在testing.B的用法示例。


在下文中一共展示了B.Get方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: BenchmarkLoadParameters

func BenchmarkLoadParameters(b *testing.B) {
	var ps FullParameters = *NewFullParameters()
	db, err := bolt.Open(path.Join("data", "testdb.db"), 0600, nil)
	if err != nil {
		Error.Println(err)
	}
	defer db.Close()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		err = db.View(func(tx *bolt.Tx) error {
			// Assume bucket exists and has keys
			b := tx.Bucket([]byte("resources"))
			if b == nil {
				return fmt.Errorf("Resources dont exist")
			}
			v := b.Get([]byte("fullParameters"))
			ps = loadParameters(v)
			return nil
		})
		if err != nil {
			Error.Println(err)
		}

	}
}
開發者ID:schollz,項目名稱:find,代碼行數:25,代碼來源:parameters_test.go

示例2: BenchmarkCalculatePosteriors1

// BenchmarkCalculatePosteriors1 needs to have precomputed parameters for testdb (run Optimize after loading testdb.sh)
func BenchmarkCalculatePosteriors1(b *testing.B) {
	res := Fingerprint{}
	jsonTest := `{"username": "zack", "group": "testdb", "wifi-fingerprint": [{"rssi": -45, "mac": "80:37:73:ba:f7:d8"}, {"rssi": -58, "mac": "80:37:73:ba:f7:dc"}, {"rssi": -61, "mac": "a0:63:91:2b:9e:65"}, {"rssi": -68, "mac": "a0:63:91:2b:9e:64"}, {"rssi": -70, "mac": "70:73:cb:bd:9f:b5"}, {"rssi": -75, "mac": "d4:05:98:57:b3:10"}, {"rssi": -75, "mac": "00:23:69:d4:47:9f"}, {"rssi": -76, "mac": "30:46:9a:a0:28:c4"}, {"rssi": -81, "mac": "2c:b0:5d:36:e3:b8"}, {"rssi": -82, "mac": "00:1a:1e:46:cd:10"}, {"rssi": -82, "mac": "20:aa:4b:b8:31:c8"}, {"rssi": -83, "mac": "e8:ed:05:55:21:10"}, {"rssi": -83, "mac": "ec:1a:59:4a:9c:ed"}, {"rssi": -88, "mac": "b8:3e:59:78:35:99"}, {"rssi": -84, "mac": "e0:46:9a:6d:02:ea"}, {"rssi": -84, "mac": "00:1a:1e:46:cd:11"}, {"rssi": -84, "mac": "f8:35:dd:0a:da:be"}, {"rssi": -84, "mac": "b4:75:0e:03:cd:69"}], "location": "zakhome floor 2 office", "time": 1439596533831, "password": "frusciante_0128"}`
	json.Unmarshal([]byte(jsonTest), &res)

	var ps FullParameters
	db, err := bolt.Open(path.Join("data", "testdb.db"), 0600, nil)
	if err != nil {
		Error.Println(err)
	}
	err = db.View(func(tx *bolt.Tx) error {
		// Assume bucket exists and has keys
		b := tx.Bucket([]byte("resources"))
		if b == nil {
			return fmt.Errorf("Resources dont exist")
		}
		v := b.Get([]byte("fullParameters"))
		ps = loadParameters(v)
		return nil
	})
	if err != nil {
		Error.Println(err)
	}
	db.Close()

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		calculatePosterior(res, ps)
	}

}
開發者ID:schollz,項目名稱:find,代碼行數:32,代碼來源:posterior_test.go

示例3: BenchmarkGet

func BenchmarkGet(b *testing.B) {
	b.StopTimer()
	if benchDb == nil {
		benchDb = newTestDb(true, 0)
		benchDb.Execute(NewTransaction(func(b *TransactionBlock) {
			b.Set("test_container", "benchget", "somevalue")
		}))
	}
	b.StartTimer()

	for i := 0; i < b.N; i++ {
		ret := benchDb.Execute(NewTransaction(func(b *TransactionBlock) {
			b.Return(b.Get("test_container", "benchget"))
		}))

		if ret.Error != nil {
			fmt.Errorf("Got an error during benchmark: %v", *ret.Error.Message)
		}
	}
}
開發者ID:appaquet,項目名稱:gostore,代碼行數:20,代碼來源:operations_test.go


注:本文中的testing.B.Get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。