本文整理匯總了Golang中testing.B.Run方法的典型用法代碼示例。如果您正苦於以下問題:Golang B.Run方法的具體用法?Golang B.Run怎麽用?Golang B.Run使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類testing.B
的用法示例。
在下文中一共展示了B.Run方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: BenchmarkScan
func BenchmarkScan(b *testing.B) {
const x = 10
for _, base := range []int{2, 8, 10, 16} {
for _, y := range []Word{10, 100, 1000, 10000, 100000} {
if isRaceBuilder && y > 1000 {
continue
}
b.Run(fmt.Sprintf("%d/Base%d", y, base), func(b *testing.B) {
b.StopTimer()
var z nat
z = z.expWW(x, y)
s := z.utoa(base)
if t := itoa(z, base); !bytes.Equal(s, t) {
b.Fatalf("scanning: got %s; want %s", s, t)
}
b.StartTimer()
for i := 0; i < b.N; i++ {
z.scan(bytes.NewReader(s), base, false)
}
})
}
}
}
示例2: BenchmarkWrite
func BenchmarkWrite(b *testing.B) {
for _, p := range hashPairs {
b.Run(p.label, func(b *testing.B) {
MultiWrite(*benchn, *benchq, p.newFunc, b)
})
}
}
示例3: BenchmarkXCryptoSum
func BenchmarkXCryptoSum(b *testing.B) {
for _, size := range sizes {
b.Run(size.name, func(b *testing.B) {
benchmarkSum(b, ref.Sum, size.l)
})
}
}
示例4: BenchmarkResize
func BenchmarkResize(b *testing.B) {
testCheckAvailable(b)
hdr := &Handler{
Executable: testExecutable,
}
params := imageserver.Params{
param: imageserver.Params{
"width": 100,
},
}
for _, tc := range []struct {
name string
im *imageserver.Image
}{
{"Small", testdata.Small},
{"Medium", testdata.Medium},
{"Large", testdata.Large},
{"Huge", testdata.Huge},
} {
b.Run(tc.name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := hdr.Handle(tc.im, params)
if err != nil {
b.Fatal(err)
}
}
})
}
}
示例5: BenchmarkErrors
func BenchmarkErrors(b *testing.B) {
var toperr error
type run struct {
stack int
std bool
}
runs := []run{
{10, false},
{10, true},
{100, false},
{100, true},
{1000, false},
{1000, true},
}
for _, r := range runs {
part := "pkg/errors"
if r.std {
part = "errors"
}
name := fmt.Sprintf("%s-stack-%d", part, r.stack)
b.Run(name, func(b *testing.B) {
var err error
f := yesErrors
if r.std {
f = noErrors
}
b.ReportAllocs()
for i := 0; i < b.N; i++ {
err = f(0, r.stack)
}
b.StopTimer()
toperr = err
})
}
}
示例6: BenchmarkVarint64ArrayMixed
// BenchmarkVarint64ArrayMixed shows the performance of lots of small messages, each
// containing a small number of large (3, 4, and 5 byte) repeated int64s.
func BenchmarkVarint64ArrayMixed(b *testing.B) {
for i := uint(1); i <= 1<<5; i <<= 1 {
dist := genUint64Dist([11]int{0, 0, 0, 4, 6, 4, 0, 0, 0, 0, 0}, int(i))
// number of sub fields
for k := uint(1); k <= 1<<10; k <<= 2 {
msg := &tpb.Message{}
for m := uint(0); m < k; m++ {
msg.Children = append(msg.Children, &tpb.Message{
Key: dist,
})
}
raw, err := proto.Marshal(msg)
if err != nil {
b.Error("wrong encode", err)
}
b.Run(fmt.Sprintf("Fields%vLen%v", k, i), func(b *testing.B) {
scratchBuf := proto.NewBuffer(nil)
b.ResetTimer()
for k := 0; k < b.N; k++ {
scratchBuf.SetBuf(raw)
msgBlackhole.Reset()
if err := scratchBuf.Unmarshal(msgBlackhole); err != nil {
b.Error("wrong decode", err)
}
}
})
}
}
}
示例7: BenchmarkClusterRestore
func BenchmarkClusterRestore(b *testing.B) {
defer tracing.Disable()()
// TODO(dan): count=10000 has some issues replicating. Investigate.
for _, numAccounts := range []int{10, 100, 1000} {
b.Run(strconv.Itoa(numAccounts), func(b *testing.B) {
ctx, dir, tc, kvDB, _, cleanupFn := backupRestoreTestSetup(b, numAccounts)
defer cleanupFn()
// TODO(dan): Once mjibson's sql -> kv function is committed, use it
// here on the output of bankDataInsert to generate the backup data
// instead of this call.
desc, err := sql.Backup(ctx, *kvDB, dir, tc.Server(0).Clock().Now())
if err != nil {
b.Fatal(err)
}
b.SetBytes(desc.DataSize)
rebalanceLeases(b, tc)
b.ResetTimer()
table := parser.TableName{DatabaseName: "bench", TableName: "bank"}
for i := 0; i < b.N; i++ {
if _, err := sql.Restore(ctx, *kvDB, dir, table); err != nil {
b.Fatal(err)
}
}
})
}
}
示例8: BenchmarkEncoder
func BenchmarkEncoder(b *testing.B) {
buf, err := ioutil.ReadFile("../testdata/e.txt")
if err != nil {
b.Fatal(err)
}
if len(buf) == 0 {
b.Fatalf("test file has no data")
}
for e := 4; e <= 6; e++ {
n := int(math.Pow10(e))
buf0 := buf
buf1 := make([]byte, n)
for i := 0; i < n; i += len(buf0) {
if len(buf0) > n-i {
buf0 = buf0[:n-i]
}
copy(buf1[i:], buf0)
}
buf0 = nil
runtime.GC()
b.Run(fmt.Sprint("1e", e), func(b *testing.B) {
b.SetBytes(int64(n))
for i := 0; i < b.N; i++ {
w := NewWriter(ioutil.Discard, LSB, 8)
w.Write(buf1)
w.Close()
}
})
}
}
示例9: BenchmarkByteBuffer
func BenchmarkByteBuffer(b *testing.B) {
input := []byte("test writing this sentence to a buffer")
b.Run("byteBuffer", func(b *testing.B) {
buf := NewByteBuffer(1024)
b.ResetTimer()
for i := 0; i < b.N; i++ {
buf.Write(input)
buf.Bytes()
buf.Reset()
}
})
b.Run("bytes.Buffer", func(b *testing.B) {
buf := bytes.NewBuffer(make([]byte, 0, 1024))
b.ResetTimer()
for i := 0; i < b.N; i++ {
buf.Write(input)
buf.Bytes()
buf.Reset()
}
})
}
示例10: BenchmarkSubnetLookup
func BenchmarkSubnetLookup(b *testing.B) {
var subnetLookup SubnetLookup
b.Run("load routes file", func(b *testing.B) {
routesData, err := ioutil.ReadFile("test_routes.dat")
if err != nil {
b.Skipf("can't load test routes file: %s", err)
}
for n := 0; n < b.N; n++ {
subnetLookup, err = NewSubnetLookupFromRoutes(routesData)
if err != nil {
b.Fatalf("NewSubnetLookup failed: %s", err)
}
}
})
if subnetLookup == nil {
b.Skipf("no test routes file")
}
b.Run("lookup random IP address", func(b *testing.B) {
for n := 0; n < b.N; n++ {
ip := make([]byte, 4)
binary.BigEndian.PutUint32(ip, rand.Uint32())
_ = subnetLookup.ContainsIPAddress(net.IP(ip))
}
})
}
示例11: BenchmarkDecoder
func BenchmarkDecoder(b *testing.B) {
buf, err := ioutil.ReadFile("../testdata/e.txt")
if err != nil {
b.Fatal(err)
}
if len(buf) == 0 {
b.Fatalf("test file has no data")
}
for e := 4; e <= 6; e++ {
n := int(math.Pow10(e))
b.Run(fmt.Sprint("1e", e), func(b *testing.B) {
b.StopTimer()
b.SetBytes(int64(n))
buf0 := buf
compressed := new(bytes.Buffer)
w := NewWriter(compressed, LSB, 8)
for i := 0; i < n; i += len(buf0) {
if len(buf0) > n-i {
buf0 = buf0[:n-i]
}
w.Write(buf0)
}
w.Close()
buf1 := compressed.Bytes()
buf0, compressed, w = nil, nil, nil
runtime.GC()
b.StartTimer()
for i := 0; i < b.N; i++ {
io.Copy(ioutil.Discard, NewReader(bytes.NewReader(buf1), LSB, 8))
}
})
}
}
示例12: BenchmarkServerGet
func BenchmarkServerGet(b *testing.B) {
srv := &Server{
Root: testdata.Dir,
}
for _, tc := range []struct {
name string
filename string
}{
{"Small", testdata.SmallFileName},
{"Medium", testdata.MediumFileName},
{"Large", testdata.LargeFileName},
{"Huge", testdata.HugeFileName},
} {
b.Run(tc.name, func(b *testing.B) {
params := imageserver.Params{
imageserver_source.Param: tc.filename,
}
var bs int
b.ResetTimer()
for i := 0; i < b.N; i++ {
im, err := srv.Get(params)
if err != nil {
b.Fatal(err)
}
bs = len(im.Data)
}
b.SetBytes(int64(bs))
})
}
}
示例13: benchmarkSizes
func benchmarkSizes(b *testing.B, sizes []int, fn func(b *testing.B, n int)) {
for _, n := range sizes {
b.Run(fmt.Sprint(n), func(b *testing.B) {
b.SetBytes(int64(n))
fn(b, n)
})
}
}
示例14: runGCD
func runGCD(b *testing.B, aSize, bSize uint) {
b.Run("WithoutXY", func(b *testing.B) {
runGCDExt(b, aSize, bSize, false)
})
b.Run("WithXY", func(b *testing.B) {
runGCDExt(b, aSize, bSize, true)
})
}
示例15: BenchmarkNewTensor
func BenchmarkNewTensor(b *testing.B) {
var (
// Some sample sizes from the Inception image labeling model.
// Where input tensors correspond to a 224x224 RGB image
// flattened into a vector.
vector [224 * 224 * 3]int32
)
b.Run("[150528]", func(b *testing.B) { benchmarkNewTensor(b, vector) })
}