当前位置: 首页>>代码示例>>Golang>>正文


Golang B.StartTimer方法代码示例

本文整理汇总了Golang中testing.B.StartTimer方法的典型用法代码示例。如果您正苦于以下问题:Golang B.StartTimer方法的具体用法?Golang B.StartTimer怎么用?Golang B.StartTimer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在testing.B的用法示例。


在下文中一共展示了B.StartTimer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: BenchmarkCacheComplete

func BenchmarkCacheComplete(b *testing.B) {
	b.StopTimer()

	paths := DefaultPaths()
	if len(paths) == 0 {
		b.Skip("No default paths available")
	}

	tests := []string{"mscorlib.dll", "System.dll"}

	c := Cache{paths: paths}
	for _, test := range tests {
		if _, err := c.Load(test); err != nil {
			b.Error(err)
		}
	}

	tests2 := []content.Type{
		content.Type{Name: content.FullyQualifiedName{Absolute: "net://type/System.String"}},
	}
	b.StartTimer()
	for i := 0; i < b.N; i++ {
		for _, test := range tests2 {
			if _, err := c.Complete(&test); err != nil {
				b.Error(err)
			}
		}
	}
}
开发者ID:berkus,项目名称:completion,代码行数:29,代码来源:cache_test.go

示例2: BenchmarkUnma

func BenchmarkUnma(b *testing.B) {
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
	total := 0

	data := new(bytes.Buffer)
	enc := gob.NewEncoder(data)
	dec := gob.NewDecoder(data)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		b.StopTimer()

		p := NewPopulatedPreAccept(popr)

		enc.Encode(p)

		total += len(data.Bytes())

		msg := &PreAccept{}

		b.StartTimer()
		dec.Decode(&msg)

	}
	b.SetBytes(int64(total / b.N))
}
开发者ID:hongchaodeng,项目名称:serialization-bench,代码行数:26,代码来源:gob_test.go

示例3: BenchmarkExist

func BenchmarkExist(b *testing.B) {
	b.StopTimer()
	var d Interface
	if opt == "slice" {
		d = newMapToSlice()
	} else {
		d = newMapToMap()
	}
	k := "A"
	for _, v := range testVals {
		d.set(k, v)
	}

	// to make it not biased towards data structures
	// with an order, such as slice.
	ix := rand.Perm(testN)

	b.StartTimer()
	b.ReportAllocs()

	for _, idx := range ix {
		if !d.exist(k, testVals[idx]) {
			b.Errorf("%s should have existed!", testVals[idx])
		}
	}
}
开发者ID:xqbumu,项目名称:learn,代码行数:26,代码来源:map_to_slice_vs_map_test.go

示例4: BenchmarkTopicToChannelPut

func BenchmarkTopicToChannelPut(b *testing.B) {
	b.StopTimer()
	log.SetOutput(ioutil.Discard)
	defer log.SetOutput(os.Stdout)
	topicName := "bench_topic_to_channel_put" + strconv.Itoa(b.N)
	channelName := "bench"
	options := NewNSQDOptions()
	options.MemQueueSize = int64(b.N)
	_, _, nsqd := mustStartNSQD(options)
	defer nsqd.Exit()
	channel := nsqd.GetTopic(topicName).GetChannel(channelName)
	b.StartTimer()

	for i := 0; i <= b.N; i++ {
		topic := nsqd.GetTopic(topicName)
		msg := nsq.NewMessage(<-nsqd.idChan, []byte("aaaaaaaaaaaaaaaaaaaaaaaaaaa"))
		topic.PutMessage(msg)
	}

	for {
		if len(channel.memoryMsgChan) == b.N {
			break
		}
		runtime.Gosched()
	}
}
开发者ID:jsocol,项目名称:nsq,代码行数:26,代码来源:topic_test.go

示例5: ReadWrite

// ReadWrite does read and write in parallel.
// qRead is num goroutines for reading.
// qWrite is num goroutines for writing.
// Assume n divisible by (qRead + qWrite).
func ReadWrite(n, qRead, qWrite int, newFunc func() HashMap, b *testing.B) {
	q := qRead + qWrite
	check(n, q)
	work := intPairArray(n)
	b.StartTimer()
	for i := 0; i < b.N; i++ { // N reps.
		h := newFunc()
		var wg sync.WaitGroup
		for j := 0; j < qRead; j++ { // Read goroutines.
			wg.Add(1)
			go func(j int) {
				defer wg.Done()
				start, end := workRange(n, q, j)
				for k := start; k < end; k++ {
					h.Get(work[k].Key)
				}
			}(j)
		}

		for j := qRead; j < q; j++ { // Write goroutines.
			wg.Add(1)
			go func(j int) {
				defer wg.Done()
				start, end := workRange(n, q, j)
				for k := start; k < end; k++ {
					h.Put(work[k].Key, work[k].Val)
				}
			}(j)
		}
		wg.Wait()
	}
}
开发者ID:dgraph-io,项目名称:experiments,代码行数:36,代码来源:benchhash.go

示例6: benchmarkClientServerParallel

func benchmarkClientServerParallel(b *testing.B, parallelism int) {
	b.ReportAllocs()
	b.StopTimer()
	handler, err := NewHandler(func(in Ping, out *Pong) error {
		if in.Data != "ping" {
			b.Fatalf("expected ping, got %q", in.Data)
		}
		out.Data = "pong"
		return nil
	})
	if err != nil {
		b.Fatalf("NewHandler: %v", err)
	}

	s := npctest.NewServer(handler)
	defer s.Close()

	c := NewClient([]string{s.Listener.Addr().String()})
	defer c.Close()
	b.SetParallelism(parallelism)
	b.StartTimer()
	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			var pong Pong
			err = c.Call(Ping{"ping"}, &pong)
			if err != nil {
				b.Fatalf("Call: %v", err)
			}
			if pong.Data != "pong" {
				b.Fatalf("expected pong, got %q", pong.Data)
			}
		}
	})
}
开发者ID:qiangmzsx,项目名称:golang,代码行数:34,代码来源:handler_test.go

示例7: BenchmarkIndex1024

func BenchmarkIndex1024(b *testing.B) {
	i := ChecksumIndex{}
	i.weakChecksumLookup = make([]map[uint32]StrongChecksumList, 256)

	for x := 0; x < 1024; x++ {
		w := rand.Uint32()

		if i.weakChecksumLookup[w&255] == nil {
			i.weakChecksumLookup[w&255] = make(map[uint32]StrongChecksumList)
		}

		i.weakChecksumLookup[w&255][w] = append(
			i.weakChecksumLookup[w&255][w],
			chunks.ChunkChecksum{},
		)
	}

	b.SetBytes(1)
	b.StartTimer()
	for x := 0; x < b.N; x++ {
		i.FindWeakChecksum2(T)
	}
	b.StopTimer()

}
开发者ID:jbreiding,项目名称:go-sync,代码行数:25,代码来源:index_bench_test.go

示例8: BenchmarkWriteBoom

func BenchmarkWriteBoom(b *testing.B) {
	if *file == "" {
		b.Skip("no file specified")
	}
	b.StopTimer()
	br, err := boom.OpenBAM(*file)
	if err != nil {
		b.Fatalf("Open failed: %v", err)
	}
	f, err := os.OpenFile("/dev/null", os.O_APPEND|os.O_RDWR, 0666)
	if err != nil {
		b.Fatalf("Open failed: %v", err)
	}
	bw, err := boom.OpenBAMFile(f, "bw", br.Header())
	if err != nil {
		b.Fatalf("NewWriter failed: %v", err)
	}
	r, _, err := br.Read()
	if err != nil {
		b.Fatalf("Read failed: %v", err)
	}
	b.StartTimer()

	for i := 0; i < b.N; i++ {
		_, err = bw.Write(r)
		if err != nil {
			b.Fatalf("Write failed: %v", err)
		}
	}

	br.Close()
	f.Close()
}
开发者ID:pombredanne,项目名称:hts,代码行数:33,代码来源:boom_benchmarks_test.go

示例9: doBenchmarkFind

func doBenchmarkFind(b *testing.B) {
	b.StopTimer()
	bas := new(basic)
	bas.Name = "Basic"
	bas.State = 3
	mg, _ := GetMigration()
	mg.DropTable(bas)
	mg.CreateTableIfNotExists(bas)
	q, _ := GetQbs()
	q.Save(bas)
	closeMigrationAndQbs(mg, q)
	b.StartTimer()
	for i := 0; i < b.N; i++ {
		ba := new(basic)
		ba.Id = 1
		q, _ = GetQbs()
		err := q.Find(ba)
		if err != nil {
			panic(err)
		}
		q.Close()
	}
	b.StopTimer()
	runtime.GC()
	stats := new(runtime.MemStats)
	runtime.ReadMemStats(stats)
	fmt.Printf("alloc:%d, total:%d\n", stats.Alloc, stats.TotalAlloc)
}
开发者ID:Neeke,项目名称:qbs,代码行数:28,代码来源:testutil_benchmark.go

示例10: doBenchmarkDbQuery

func doBenchmarkDbQuery(b *testing.B) {
	b.StopTimer()
	bas := new(basic)
	bas.Name = "Basic"
	bas.State = 3
	mg, _ := GetMigration()
	mg.DropTable(bas)
	mg.CreateTableIfNotExists(bas)
	q, _ := GetQbs()
	q.Save(bas)
	closeMigrationAndQbs(mg, q)
	b.StartTimer()
	db, _ := sql.Open(driver, driverSource)
	query := q.Dialect.substituteMarkers("SELECT * FROM basic WHERE id = ?")
	for i := 0; i < b.N; i++ {
		ba := new(basic)
		rows, err := db.Query(query, 1)
		if err != nil {
			panic(err)
		}
		rows.Next()
		err = rows.Scan(&ba.Id, &ba.Name, &ba.State)
		if err != nil {
			panic(err)
		}
		rows.Close()
	}
	db.Close()
	b.StopTimer()
	runtime.GC()
	stats := new(runtime.MemStats)
	runtime.ReadMemStats(stats)
	fmt.Printf("alloc:%d, total:%d\n", stats.Alloc, stats.TotalAlloc)
}
开发者ID:Neeke,项目名称:qbs,代码行数:34,代码来源:testutil_benchmark.go

示例11: BenchmarkRoute2DB1

func BenchmarkRoute2DB1(b *testing.B) {

	b.StopTimer()
	var sp Sparrow
	sp.Initialize(nil)
	b.StartTimer()
	for i := 0; i < b.N; i++ {

		rc, err := sp.Route2DB("db", "table", "user_id", "id0041", false, false)
		if err != nil {

			b.Error(err)

		}
		if rc == nil || rc.DBNode == nil || len(rc.DBName) <= 0 || len(rc.TableName) <= 0 {

			b.Errorf("dbatom:%v, dbname: %v, tablename:%v\n", rc.DBNode, rc.DBName, rc.TableName)
		}
		if rc.DBNode.IsMaster {

			b.Errorf("dbname: %s, tablename: %d, should not be master.", rc.DBNode.Ip, rc.DBNode.Port)
		}
		if !rc.DBNode.DBEnable {

			b.Errorf("dbname: %s, tablename: %d, disable.", rc.DBNode.Ip, rc.DBNode.Port)
		}
	}
}
开发者ID:yujinliang,项目名称:sparrow,代码行数:28,代码来源:dbshard_test.go

示例12: BenchmarkSealLongMsg

// Benchmark sealing a 1MiB message.
func BenchmarkSealLongMsg(b *testing.B) {
	b.StopTimer()
	msg, err := ioutil.ReadFile("testdata/long.dat")
	if err != nil {
		fmt.Println("secretbox: failed to read short test message")
		fmt.Printf("%v\n", err)
		b.FailNow()
	}
	longMsg = msg
	b.StartTimer()

	for i := 0; i < b.N; i++ {
		_, ok := Seal(msg, testKey)
		if !ok {
			fmt.Println("secretbox: failed to seal message")
			b.FailNow()
		}
		b.SetBytes(int64(len(msg)))
	}
	b.StopTimer()

	var ok bool
	longBox, ok = Seal(msg, testKey)
	if !ok {
		fmt.Println("secretbox: failed to seal message")
		b.FailNow()
	}
}
开发者ID:postfix,项目名称:cryptobox-ng,代码行数:29,代码来源:secretbox_test.go

示例13: BenchmarkGorillaMux

func BenchmarkGorillaMux(b *testing.B) {
	b.StopTimer()
	http.DefaultServeMux = http.NewServeMux()
	r := mux.NewRouter()
	r.HandleFunc("/heroku/resources", fakehandler).
		Methods("POST")
	r.HandleFunc("/heroku/delete", fakehandler).
		Methods("DELETE")
	ts := httptest.NewServer(r)
	defer ts.Close()
	b.StartTimer()

	for i := 0; i < b.N; i++ {
		res, err := http.Post(ts.URL+"/heroku/resources", "text", strings.NewReader(""))
		if err != nil {
			b.Fatal("Post:", err)
		}
		_, err = ioutil.ReadAll(res.Body)
		if err != nil {
			b.Fatal("ReadAll:", err)
		}
	}

	b.StopTimer()
}
开发者ID:kr,项目名称:webx,代码行数:25,代码来源:main_test.go

示例14: RunBenchmark

func RunBenchmark(b *testing.B, suite string, name string, specificLogic func(b *testing.B, doc *XmlDocument)) {
	b.StopTimer()

	//	defer CheckXmlMemoryLeaks(b)

	input, _, error := getTestData(filepath.Join("tests", suite, name))

	if len(error) > 0 {
		panic(fmt.Sprintf("Error gathering test data for %v:\n%v\n", name, error))
	}

	doc, err := parseInput(input)

	if err != nil {
		panic("Error:" + err.Error())
	}

	b.StartTimer()

	if specificLogic != nil {
		specificLogic(b, doc)
	}

	doc.Free()

	//	println("----------- END OF BENCHMARK -----------")
}
开发者ID:jbowtie,项目名称:gokogiri,代码行数:27,代码来源:utils_test.go

示例15: BenchmarkClientServer

func BenchmarkClientServer(b *testing.B) {
	b.StopTimer()
	ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(rw, "Hello world.\n")
	}))
	defer ts.Close()
	b.StartTimer()

	for i := 0; i < b.N; i++ {
		res, err := http.Get(ts.URL)
		if err != nil {
			b.Fatal("Get:", err)
		}
		all, err := ioutil.ReadAll(res.Body)
		if err != nil {
			b.Fatal("ReadAll:", err)
		}
		body := string(all)
		if body != "Hello world.\n" {
			b.Fatal("Got body:", body)
		}
	}

	b.StopTimer()
}
开发者ID:nanha,项目名称:gorouter,代码行数:25,代码来源:server_test.go


注:本文中的testing.B.StartTimer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。