本文整理汇总了Golang中testing.B.Logf方法的典型用法代码示例。如果您正苦于以下问题:Golang B.Logf方法的具体用法?Golang B.Logf怎么用?Golang B.Logf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testing.B
的用法示例。
在下文中一共展示了B.Logf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BenchmarkVersion
func BenchmarkVersion(b *testing.B) {
ufs := new(ufs.Ufs)
ufs.Dotu = false
ufs.Id = "ufs"
ufs.Debuglevel = *debug
ufs.Msize = 8192
ufs.Start(ufs)
l, err := net.Listen("unix", "")
if err != nil {
b.Fatalf("Can not start listener: %v", err)
}
srvAddr := l.Addr().String()
b.Logf("Server is at %v", srvAddr)
go func() {
if err = ufs.StartListener(l); err != nil {
b.Fatalf("Can not start listener: %v", err)
}
b.Fatalf("Listener returned")
}()
var conn net.Conn
for i := 0; i < b.N; i++ {
if conn, err = net.Dial("unix", srvAddr); err != nil {
// Sometimes, things just happen.
//b.Logf("%v", err)
} else {
conn.Close()
}
}
}
示例2: BenchmarkTop10of100000Scores
func BenchmarkTop10of100000Scores(b *testing.B) {
matches := make(search.DocumentMatchCollection, 0, 100000)
for i := 0; i < 100000; i++ {
matches = append(matches, &search.DocumentMatch{
ID: strconv.Itoa(i),
Score: rand.Float64(),
})
}
searcher := &stubSearcher{
matches: matches,
}
collector := NewTopScorerCollector(10)
b.ResetTimer()
err := collector.Collect(searcher)
if err != nil {
b.Fatal(err)
}
res := collector.Results()
for _, dm := range res {
b.Logf("%s - %f\n", dm.ID, dm.Score)
}
}
示例3: BenchmarkGraphiteMemory
func BenchmarkGraphiteMemory(b *testing.B) {
cfg := config.ConfigFile{}
cfg.Graphite = config.GraphiteConfig{
UDPListenPort: ":2000",
}
errorChannel := make(chan error, 1)
go func() {
for e := range errorChannel {
b.Logf("%s", e)
}
}()
p := ":2000"
l := "/tmp/agent.db"
ttl := "1h"
aggregations.Init(&p, &l, &ttl, errorChannel)
Init(&cfg, errorChannel)
for n := 0; n < b.N; n++ {
testGraphiteMemoryRun(b, 1)
}
}
示例4: BenchmarkAPIHandler
func BenchmarkAPIHandler(b *testing.B) {
app := testMemoryAppWithClients(1, 100)
nCommands := 1000
b.Logf("num channels: %v, num clients: %v, num unique clients %v, num commands: %v", app.clients.nChannels(), app.clients.nClients(), app.clients.nUniqueClients(), nCommands)
commands := make([]map[string]interface{}, nCommands)
command := map[string]interface{}{
"method": "publish",
"params": map[string]interface{}{
"channel": "channel-0",
"data": map[string]bool{"benchmarking": true},
},
}
for i := 0; i < nCommands; i++ {
commands[i] = command
}
jsonData, _ := json.Marshal(commands)
sign := auth.GenerateApiSign("secret", "test1", jsonData)
b.ResetTimer()
for i := 0; i < b.N; i++ {
rec := httptest.NewRecorder()
req, _ := http.NewRequest("POST", "/api/test1", bytes.NewBuffer(jsonData))
req.Header.Add("X-API-Sign", sign)
req.Header.Add("Content-Type", "application/json")
app.APIHandler(rec, req)
}
b.StopTimer()
}
示例5: BenchmarkPublish
func BenchmarkPublish(b *testing.B) {
ps := &PubSub{}
c := make(chan int)
ready := make(chan int)
go func() {
total := 0
for i := range c {
total += i
}
ready <- total
}()
s := ps.Subscribe(func(int) {
c <- 1
})
for i := 0; i < b.N; i++ {
ps.Publish(10)
time.Sleep(1 * time.Microsecond)
}
s.Close()
close(c)
timer := time.NewTicker(5 * time.Second)
var total int
select {
case <-timer.C:
b.Fatal("timeout waiting for total")
case total = <-ready:
}
b.Logf("%d: %+v", total, ps.Stats)
}
示例6: BenchmarkUpdateFast
// Ideally should perform much better than both BenchmarkUpdateDumb and
// BenchmarkUpdateWorst.
func BenchmarkUpdateFast(b *testing.B) {
objs := benchObjs
for len(objs) < nUpdateObjects {
objs = append(objs, random())
}
benchObjs = objs
tree := New()
for _, o := range objs {
tree.Add(o)
}
b.ResetTimer()
fail := 0
success := 0
for n := 0; n < b.N; n++ {
oldIndex := n % len(objs)
oldObj := objs[oldIndex]
newObj := offset(oldObj.(gfx.Bounds))
if !tree.Update(oldObj, newObj) {
fail++
} else {
success++
}
objs[oldIndex] = newObj
}
if fail > 0 {
b.Logf("Update failure ratio: fail=%d success=%d.", fail, success)
b.Fail()
}
}
示例7: benchmarkChunker
func benchmarkChunker(b *testing.B, hash hash.Hash) {
size := 10 * 1024 * 1024
rd := bytes.NewReader(getRandom(23, size))
b.ResetTimer()
b.SetBytes(int64(size))
var chunks int
for i := 0; i < b.N; i++ {
chunks = 0
rd.Seek(0, 0)
ch := chunker.New(rd, testPol, hash)
for {
_, err := ch.Next()
if err == io.EOF {
break
}
if err != nil {
b.Fatalf("Unexpected error occurred: %v", err)
}
chunks++
}
}
b.Logf("%d chunks, average chunk size: %d bytes", chunks, size/chunks)
}
示例8: BenchmarkDelete
func BenchmarkDelete(b *testing.B) {
var objmap interface{}
client := Client{Organization: "yourorgname", Application: "sandbox", Uri: "https://api.usergrid.com"}
params := map[string]string{"limit": strconv.Itoa(500)}
err := client.Get("benchmark", params, JSONResponseHandler(&objmap))
if err != nil {
b.Logf("Test failed: %s\n", err)
b.Fail()
}
omap := objmap.(map[string]interface{})
if omap["entities"] == nil || len(omap["entities"].([]interface{})) == 0 {
b.Logf("Test failed: no entities to delete\n")
b.Fail()
}
entities := omap["entities"].([]interface{})
var entity map[string]interface{}
b.ResetTimer()
for i := 0; i < b.N; i++ {
if len(entities) == 0 {
b.Logf("Test failed: we ran out of entities\n")
b.Fail()
continue
}
entity, entities = entities[len(entities)-1].(map[string]interface{}), entities[:len(entities)-1]
err := client.Delete("benchmark/"+entity["uuid"].(string), nil, NOOPResponseHandler(&objmap))
if err != nil {
b.Logf("BenchmarkDelete failed: %s\n", err)
b.Fail()
}
}
if b.Failed() {
str, _ := json.MarshalIndent(objmap, "", " ")
b.Logf("RESPONSE: %s", str)
}
}
示例9: BenchmarkConcurrentMap
func BenchmarkConcurrentMap(b *testing.B) {
keyType := reflect.TypeOf(int32(2))
elemType := keyType
cmap := NewConcurrentMap(keyType, elemType)
var key, elem int32
fmt.Printf("N=%d.\n", b.N)
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
seed := int32(i)
key = seed
elem = seed << 10
b.StartTimer()
cmap.Put(key, elem)
_ = cmap.Get(key)
b.StopTimer()
b.SetBytes(8)
b.StartTimer()
}
ml := cmap.Len()
b.StopTimer()
mapType := fmt.Sprintf("ConcurrentMap<%s, %s>",
keyType.Kind().String(), elemType.Kind().String())
b.Logf("The length of %s value is %d.\n", mapType, ml)
b.StartTimer()
}
示例10: BenchmarkMap
func BenchmarkMap(b *testing.B) {
keyType := reflect.TypeOf(int32(2))
elemType := keyType
imap := make(map[interface{}]interface{})
var key, elem int32
fmt.Printf("N=%d.\n", b.N)
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StopTimer()
seed := int32(i)
key = seed
elem = seed << 10
b.StartTimer()
imap[key] = elem
b.StopTimer()
_ = imap[key]
b.StopTimer()
b.SetBytes(8)
b.StartTimer()
}
ml := len(imap)
b.StopTimer()
mapType := fmt.Sprintf("Map<%s, %s>",
keyType.Kind().String(), elemType.Kind().String())
b.Logf("The length of %s value is %d.\n", mapType, ml)
b.StartTimer()
}
示例11: BenchmarkExtract
func BenchmarkExtract(b *testing.B) {
config, err := ioutil.ReadFile("test/recursor_stats.json")
if err != nil {
b.Fatalf("could not read config file: %v", err.Error())
}
h := newPowerDNS(config)
defer h.Close()
hostURL, _ := url.Parse(h.URL)
e := NewExporter("12345", "recursor", hostURL)
var before, after runtime.MemStats
runtime.GC()
runtime.ReadMemStats(&before)
b.ResetTimer()
for i := 0; i < b.N; i++ {
ch := make(chan prometheus.Metric)
go func(ch chan prometheus.Metric) {
for _ = range ch {
}
}(ch)
e.Collect(ch)
close(ch)
}
runtime.GC()
runtime.ReadMemStats(&after)
b.Logf("%d bytes used after %d runs", after.Alloc-before.Alloc, b.N)
}
示例12: BenchmarkMetalReviewExample
func BenchmarkMetalReviewExample(b *testing.B) {
var n int
var buf bytes.Buffer
b.StopTimer()
doc := LoadDoc("metalreview.html")
b.StartTimer()
for i := 0; i < b.N; i++ {
doc.Find(".slider-row:nth-child(1) .slider-item").Each(func(i int, s *Selection) {
var band, title string
var score float64
var e error
n++
// For each item found, get the band, title and score, and print it
band = s.Find("strong").Text()
title = s.Find("em").Text()
if score, e = strconv.ParseFloat(s.Find(".score").Text(), 64); e != nil {
// Not a valid float, ignore score
if n <= 4 {
buf.WriteString(fmt.Sprintf("Review %d: %s - %s.\n", i, band, title))
}
} else {
// Print all, including score
if n <= 4 {
buf.WriteString(fmt.Sprintf("Review %d: %s - %s (%2.1f).\n", i, band, title, score))
}
}
})
}
b.Log(buf.String())
b.Logf("MetalReviewExample=%d", n)
}
示例13: BenchmarkToJSON2
func BenchmarkToJSON2(b *testing.B) {
var (
vals = make([]bench3.Bench, b.N)
res = []byte{}
err error
)
for i := 0; i < b.N; i++ {
vals[i] = bench3.NewBench("demo", 42, json.Marshal)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
res, err = vals[i].ToJSON()
if err != nil {
b.Logf("Failed test: %d with error: %q", i, err)
b.Fail()
}
}
b.StopTimer()
byteEncoded = res
runtime.GC()
}
示例14: BenchmarkToJSONString2
func BenchmarkToJSONString2(b *testing.B) {
var (
vals = make([]bench2.Bench, b.N)
res = ""
err error
)
for i := 0; i < b.N; i++ {
vals[i] = bench2.Bench{FieldA: "demo", FieldB: 42}
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
res, err = vals[i].ToJSONString2()
if err != nil {
b.Logf("Failed test: %d with error: %q", i, err)
b.Fail()
}
}
b.StopTimer()
stringEncoded = res
runtime.GC()
}
示例15: benchmarkThrottlerParallel
// benchmarkThrottlerParallel is the parallel version of benchmarkThrottler.
// Set -cpu to change the number of threads. The QPS should be distributed
// across all threads and the reported benchmark value should be similar
// to the value of benchmarkThrottler.
func benchmarkThrottlerParallel(b *testing.B, qps int64) {
threadCount := runtime.GOMAXPROCS(0)
throttler, _ := NewThrottler("test", "queries", threadCount, qps, ReplicationLagModuleDisabled)
defer throttler.Close()
threadIDs := make(chan int, threadCount)
for id := 0; id < threadCount; id++ {
threadIDs <- id
}
close(threadIDs)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
threadID := <-threadIDs
for pb.Next() {
backedOff := 0
for {
backoff := throttler.Throttle(threadID)
if backoff == NotThrottled {
break
}
backedOff++
if backedOff > 1 {
b.Logf("did not wait long enough after backoff. threadID = %v, last backoff = %v", threadID, backoff)
}
time.Sleep(backoff)
}
}
throttler.ThreadFinished(threadID)
})
}