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


Golang B.ReportAllocs方法代码示例

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


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

示例1: BenchmarkHeaderWriteSubset

func BenchmarkHeaderWriteSubset(b *testing.B) {
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		buf.Reset()
		testHeader.WriteSubset(&buf, nil)
	}
}
开发者ID:kostyll,项目名称:gccpy,代码行数:7,代码来源:header_test.go

示例2: Benchmark_MoneyNewGetf

// Benchmark_MoneyNewGetf	 2000000	       771 ns/op	     208 B/op	       7 allocs/op => Go 1.4.2
// Benchmark_MoneyNewGetf  	 3000000	       404 ns/op	     160 B/op	       3 allocs/op => Go 1.5.0
func Benchmark_MoneyNewGetf(b *testing.B) {
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		c := money.New(money.WithPrecision(100)).Setf(-123456.789)
		benchmarkMoneyNewGetf = c.Getf()
	}
}
开发者ID:joao-parana,项目名称:csfw,代码行数:9,代码来源:money_bm_test.go

示例3: BenchmarkConcurrentRandom

func BenchmarkConcurrentRandom(b *testing.B) {
	b.ReportAllocs()
	ct := new(concurrentRandomTest)
	for i := 0; i < b.N; i++ {
		doConcurrentTest(b, ct)
	}
}
开发者ID:maqayum,项目名称:gcc-libitm,代码行数:7,代码来源:sql_test.go

示例4: BenchmarkClientServer

func BenchmarkClientServer(b *testing.B) {
	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.StartTimer()
	for i := 0; i < b.N; i++ {
		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,代码行数:32,代码来源:handler_test.go

示例5: BenchmarkHandlerCall

func BenchmarkHandlerCall(b *testing.B) {

	fn := func(params *jsonrpc2.EmptyParams) (interface{}, error) {

		return nil, nil
	}

	handler := handler{
		method: reflect.ValueOf(fn),
		params: reflect.New(reflect.ValueOf(fn).Type().In(0).Elem()).Interface().(jsonrpc2.Params),
	}
	data, _ := json.Marshal(&jsonrpc2.EmptyParams{})

	params, err := handler.DecodeParams(data)

	if err != nil {

		b.Fatal(err.Error())
	}

	b.ResetTimer()
	b.ReportAllocs()

	for i := 0; i < b.N; i++ {

		handler.Call(params)
	}
}
开发者ID:kshvakov,项目名称:jsonrpc2,代码行数:28,代码来源:handler_benchmark_test.go

示例6: BenchmarkNew

func BenchmarkNew(b *testing.B) {
	b.ReportAllocs()

	for i := 0; i < b.N; i++ {
		hdrhistogram.New(1, 120000, 3) // this could track 1ms-2min
	}
}
开发者ID:mikespokefire,项目名称:maraxy,代码行数:7,代码来源:hdr_test.go

示例7: benchmarkDecodeFile

func benchmarkDecodeFile(path string, b *testing.B) {
	b.ReportAllocs()
	p := "fixtures/" + path
	for n := 0; n < b.N; n++ {
		DecodeFile(p)
	}
}
开发者ID:billyboar,项目名称:GCSolutions,代码行数:7,代码来源:decoder_test.go

示例8: BenchmarkManyConcurrentQueries

func BenchmarkManyConcurrentQueries(b *testing.B) {
	b.ReportAllocs()
	// To see lock contention in Go 1.4, 16~ cores and 128~ goroutines are required.
	const parallelism = 16

	db := newTestDB(b, "magicquery")
	defer closeDB(b, db)
	db.SetMaxIdleConns(runtime.GOMAXPROCS(0) * parallelism)

	stmt, err := db.Prepare("SELECT|magicquery|op|op=?,millis=?")
	if err != nil {
		b.Fatal(err)
	}
	defer stmt.Close()

	b.SetParallelism(parallelism)
	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			rows, err := stmt.Query("sleep", 1)
			if err != nil {
				b.Error(err)
				return
			}
			rows.Close()
		}
	})
}
开发者ID:pjump,项目名称:gcc,代码行数:27,代码来源:sql_test.go

示例9: benchmarkConnections

func benchmarkConnections(b *testing.B) {
	b.ReportAllocs()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		cbConnections(false)
	}
}
开发者ID:paulbellamy,项目名称:procspy,代码行数:7,代码来源:benchmark_test.go

示例10: BenchmarkSendWithContext

func BenchmarkSendWithContext(b *testing.B) {
	incrHandler := IncrHandler{}

	destination := HandlerFunc(func(ctx context.Context, rw http.ResponseWriter, r *http.Request) {
		b.StopTimer()
		rw.Write(ctx.Value("towrite").([]byte))
		b.StartTimer()
	})

	ctx := context.Background()
	h := NewHandler(ctx, HandlerFunc(destination)).Add(NextConstructor(addTowrite), HTTPConstructor(incrHandler.makeHTTP))

	b.ReportAllocs()
	b.ResetTimer()
	b.StopTimer()
	for j := 0; j < b.N; j++ {
		rw := httptest.NewRecorder()
		req, _ := http.NewRequest("POST", "/", nil)
		req.Header.Add("towrite", fmt.Sprintf("%d", j))
		b.StartTimer()
		h.ServeHTTP(rw, req)
		b.StopTimer()
		assert.Equal(b, fmt.Sprintf("%d", j), rw.Body.String())
	}
}
开发者ID:baris,项目名称:metricproxy,代码行数:25,代码来源:web_test.go

示例11: benchmarkServerQueryCount

func benchmarkServerQueryCount(b *testing.B, pointN int) {
	s := OpenDefaultServer(NewConfig())
	defer s.Close()

	// Write data into server.
	var buf bytes.Buffer
	for i := 0; i < pointN; i++ {
		fmt.Fprintf(&buf, `cpu value=100 %d`, i+1)
		if i != pointN-1 {
			fmt.Fprint(&buf, "\n")
		}
	}
	s.MustWrite("db0", "rp0", buf.String(), nil)

	// Query simple count from server.
	b.ResetTimer()
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		if results, err := s.Query(`SELECT count(value) FROM db0.rp0.cpu`); err != nil {
			b.Fatal(err)
		} else if results != fmt.Sprintf(`{"results":[{"series":[{"name":"cpu","columns":["time","count"],"values":[["1970-01-01T00:00:00Z",%d]]}]}]}`, pointN) {
			b.Fatalf("unexpected result: %s", results)
		}
	}
}
开发者ID:seiflotfy,项目名称:influxdb,代码行数:25,代码来源:server_bench_test.go

示例12: Benchmark_WithInitStoreByFormCookie

// Benchmark_WithInitStoreByFormCookie-4	    3000	    481881 ns/op	  189103 B/op	     232 allocs/op => with debug enabled
// Benchmark_WithInitStoreByFormCookie-4	  300000	      4797 ns/op	    1016 B/op	      16 allocs/op => debug disabled
func Benchmark_WithInitStoreByFormCookie(b *testing.B) {
	store.PkgLog.SetLevel(log.StdLevelInfo)
	b.ReportAllocs()

	wantStoreCode := "nz"
	ctx := store.NewContextReader(context.Background(), getInitializedStoreService(scope.Option{Website: scope.MockID(2)}))

	mw := store.WithInitStoreByFormCookie()(benchValidationHandler(b, wantStoreCode))

	rec := httptest.NewRecorder()
	req, err := http.NewRequest(httputils.MethodGet, "https://corestore.io/store/list/", nil)
	if err != nil {
		b.Fatal(err)
	}

	req.AddCookie(&http.Cookie{
		Name:  store.ParamName,
		Value: wantStoreCode,
	})

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		if err := mw.ServeHTTPContext(ctx, rec, req); err != nil {
			b.Error(err)
		}
	}
}
开发者ID:levcom,项目名称:csfw,代码行数:29,代码来源:middleware_bm_test.go

示例13: Benchmark_WithValidateBaseUrl

// Benchmark_WithValidateBaseUrl-4         	    3000	    489089 ns/op	  188333 B/op	     272 allocs/op => with debug enabled
// Benchmark_WithValidateBaseUrl-4         	  200000	      8925 ns/op	    2924 B/op	      49 allocs/op => no debug
func Benchmark_WithValidateBaseUrl(b *testing.B) {
	// todo: there is room for optimization with disabled debugging. too many allocs
	store.PkgLog.SetLevel(log.StdLevelInfo)
	req, err := http.NewRequest(httputils.MethodGet, "https://corestore.io/customer/comments/view?id=1916#tab=ratings", nil)
	if err != nil {
		b.Fatal(err)
	}

	finalHandler := store.WithValidateBaseURL(middlewareConfigReader)(ctxhttp.HandlerFunc(func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
		return errors.New("This handler should not be called!")
	}))
	want := "https://www.corestore.io/customer/comments/view?id=1916#tab=ratings"
	rec := httptest.NewRecorder()
	b.ReportAllocs()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		if err := finalHandler.ServeHTTPContext(middlewareCtxStoreService, rec, req); err != nil {
			b.Error(err)
		}
		if rec.HeaderMap.Get("Location") != want {
			b.Errorf("Have: %s\nWant: %s", rec.HeaderMap.Get("Location"), want)
		}
		rec.HeaderMap = nil
	}
}
开发者ID:levcom,项目名称:csfw,代码行数:27,代码来源:middleware_bm_test.go

示例14: BenchmarkIsNotIoError

func BenchmarkIsNotIoError(b *testing.B) {
	b.ReportAllocs()
	err := errors.New("blah")
	for i := 0; i < b.N; i++ {
		IsIoError(err)
	}
}
开发者ID:lucmichalski,项目名称:fae,代码行数:7,代码来源:bench_test.go

示例15: benchInsertChain

func benchInsertChain(b *testing.B, disk bool, gen func(int, *BlockGen)) {
	// Create the database in memory or in a temporary directory.
	var db ethdb.Database
	if !disk {
		db, _ = ethdb.NewMemDatabase()
	} else {
		dir, err := ioutil.TempDir("", "exp-core-bench")
		if err != nil {
			b.Fatalf("cannot create temporary directory: %v", err)
		}
		defer os.RemoveAll(dir)
		db, err = ethdb.NewLDBDatabase(dir, 0)
		if err != nil {
			b.Fatalf("cannot create temporary database: %v", err)
		}
		defer db.Close()
	}

	// Generate a chain of b.N blocks using the supplied block
	// generator function.
	genesis := WriteGenesisBlockForTesting(db, GenesisAccount{benchRootAddr, benchRootFunds})
	chain, _ := GenerateChain(genesis, db, b.N, gen)

	// Time the insertion of the new chain.
	// State and blocks are stored in the same DB.
	evmux := new(event.TypeMux)
	chainman, _ := NewBlockChain(db, FakePow{}, evmux)
	defer chainman.Stop()
	b.ReportAllocs()
	b.ResetTimer()
	if i, err := chainman.InsertChain(chain); err != nil {
		b.Fatalf("insert error (block %d): %v\n", i, err)
	}
}
开发者ID:Cisko-Rijken,项目名称:go-expanse,代码行数:34,代码来源:bench_test.go


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