本文整理汇总了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)
}
}
}
}
示例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))
}
示例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])
}
}
}
示例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()
}
}
示例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()
}
}
示例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)
}
}
})
}
示例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()
}
示例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()
}
示例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)
}
示例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)
}
示例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)
}
}
}
示例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()
}
}
示例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()
}
示例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 -----------")
}
示例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()
}