本文整理汇总了Golang中testing.B.Fatal方法的典型用法代码示例。如果您正苦于以下问题:Golang B.Fatal方法的具体用法?Golang B.Fatal怎么用?Golang B.Fatal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testing.B
的用法示例。
在下文中一共展示了B.Fatal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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()
}
示例2: BenchmarkConnStress
func BenchmarkConnStress(b *testing.B) {
const workers = 16
cluster := createCluster()
cluster.NumConns = 1
session := createSessionFromCluster(cluster, b)
defer session.Close()
if err := createTable(session, "CREATE TABLE IF NOT EXISTS conn_stress (id int primary key)"); err != nil {
b.Fatal(err)
}
var seed uint64
writer := func(pb *testing.PB) {
seed := atomic.AddUint64(&seed, 1)
var i uint64 = 0
for pb.Next() {
if err := session.Query("insert into conn_stress (id) values (?)", i*seed).Exec(); err != nil {
b.Error(err)
return
}
i++
}
}
b.SetParallelism(workers)
b.RunParallel(writer)
}
示例3: benchPutItemParallel
func benchPutItemParallel(p, c int, b *testing.B) {
svc := dynamodb.New(&aws.Config{
DisableSSL: aws.Bool(true),
})
av, err := dynamodbattribute.ConvertToMap(dbItem{Key: "MyKey", Data: "MyData"})
if err != nil {
b.Fatal("expect no ConvertToMap errors", err)
}
params := &dynamodb.PutItemInput{
Item: av,
TableName: aws.String(testTableName),
}
b.N = c
b.ResetTimer()
b.SetParallelism(p)
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_, err = svc.PutItem(params)
if err != nil {
b.Error("expect no request errors", err)
}
}
})
}
示例4: BenchmarkFilterPatterns
func BenchmarkFilterPatterns(b *testing.B) {
patterns := []string{
"sdk/*",
"*.html",
}
lines := extractTestLines(b)
var c uint
b.ResetTimer()
for i := 0; i < b.N; i++ {
c = 0
for _, line := range lines {
match, err := filter.List(patterns, line)
if err != nil {
b.Fatal(err)
}
if match {
c++
}
}
if c != 22185 {
b.Fatalf("wrong number of matches: expected 22185, got %d", c)
}
}
}
示例5: BenchmarkSmall
func BenchmarkSmall(t *testing.B) {
for i := 0; i < t.N; i++ {
if _, err := ParseString(SmallJson); err != nil {
t.Fatal(err)
}
}
}
示例6: benchmarkBTreeSetRollbackFiler
func benchmarkBTreeSetRollbackFiler(b *testing.B, sz int) {
dir, testDbName := temp()
defer os.RemoveAll(dir)
f, err := os.OpenFile(testDbName, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0600)
if err != nil {
b.Fatal(err)
}
defer f.Close()
g := NewSimpleFileFiler(f)
var filer *RollbackFiler
if filer, err = NewRollbackFiler(
g,
func(sz int64) error {
if err = g.Truncate(sz); err != nil {
return err
}
return g.Sync()
},
g,
); err != nil {
b.Error(err)
return
}
benchmarkBTreeSetFiler(b, filer, sz)
}
示例7: benchmarkEndToEnd
func benchmarkEndToEnd(dial func() (*Client, error), b *testing.B) {
b.StopTimer()
once.Do(startServer)
client, err := dial()
if err != nil {
b.Fatal("error dialing:", err)
}
// Synchronous calls
args := &Args{7, 8}
procs := runtime.GOMAXPROCS(-1)
N := int32(b.N)
var wg sync.WaitGroup
wg.Add(procs)
b.StartTimer()
for p := 0; p < procs; p++ {
go func() {
reply := new(Reply)
for atomic.AddInt32(&N, -1) >= 0 {
err := client.Call("Arith.Add", args, reply)
if err != nil {
b.Fatalf("rpc error: Add: expected no error but got string %q", err.Error())
}
if reply.C != args.A+args.B {
b.Fatalf("rpc error: Add: expected %d got %d", reply.C, args.A+args.B)
}
}
wg.Done()
}()
}
wg.Wait()
}
示例8: BenchmarkAppendRaw
// Benchmarking raw mgo queries.
func BenchmarkAppendRaw(b *testing.B) {
sess, err := db.Open(Adapter, settings)
if err != nil {
b.Fatal(err)
}
defer sess.Close()
artist, err := sess.Collection("artist")
artist.Truncate()
driver := sess.Driver().(*mgo.Session)
mgodb := driver.DB(database)
col := mgodb.C("artist")
b.ResetTimer()
for i := 0; i < b.N; i++ {
err := col.Insert(map[string]string{"name": "Hayao Miyazaki"})
if err != nil {
b.Fatal(err)
}
}
}
示例9: BenchmarkInterfaceAddrs
func BenchmarkInterfaceAddrs(b *testing.B) {
for i := 0; i < b.N; i++ {
if _, err := InterfaceAddrs(); err != nil {
b.Fatal(err)
}
}
}
示例10: BenchmarkLanguage
func BenchmarkLanguage(b *testing.B) {
b.StopTimer()
tst := []string{
"language.go",
"testdata/main.go",
}
var d0 []string
for _, s := range tst {
if d, err := ioutil.ReadFile(s); err != nil {
b.Errorf("Couldn't load file %s: %s", s, err)
} else {
d0 = append(d0, string(d))
}
}
b.StartTimer()
for i := 0; i < b.N; i++ {
for j := range d0 {
lp, err := NewLanguageParser("testdata/Go.tmLanguage", d0[j])
if err != nil {
b.Fatal(err)
return
}
lp.Parse()
}
}
fmt.Println(util.Prof)
}
示例11: BenchmarkAll
func BenchmarkAll(b *testing.B) {
stds, err := exec.Command("go", "list", "std").Output()
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
pkgNames := strings.Fields(string(stds))
for _, c := range contexts {
c.Compiler = build.Default.Compiler
}
for i := 0; i < b.N; i++ {
for _, context := range contexts {
w := NewWalker(context, filepath.Join(build.Default.GOROOT, "src"))
for _, name := range pkgNames {
if name != "unsafe" && !strings.HasPrefix(name, "cmd/") {
pkg, _ := w.Import(name)
w.export(pkg)
}
}
w.Features()
}
}
}
示例12: BenchmarkDecodeStruct
func BenchmarkDecodeStruct(b *testing.B) {
type s1 struct {
Atom types.Atom
priv0 int
Uint8 uint8
Uint16 uint16
Uint32 uint32
priv1 string
Byte byte
Int int
priv2 *s1
List []s1
Binary []byte
}
data := []byte{
131, 104, 8, 100, 0, 12, 116, 104, 105, 115, 32, 105, 115, 32, 97, 116, 111,
109, 97, 255, 98, 0, 0, 255, 255, 110, 4, 0, 255, 255, 255, 255, 97, 128, 98,
255, 255, 253, 102, 106, 107, 0, 5, 1, 2, 3, 4, 5,
}
in := bytes.NewBuffer(data)
var v s1
err := Decode(in, &v)
if err != nil {
b.Fatal(err)
} else if l := in.Len(); l != 0 {
b.Fatalf("buffer len %d", l)
}
for i := 0; i < b.N; i++ {
in = bytes.NewBuffer(data)
err = Decode(in, &v)
}
}
示例13: BenchmarkUsersProd
func BenchmarkUsersProd(b *testing.B) {
prodfile := "./prods/users.prod"
text, err := ioutil.ReadFile(prodfile)
if err != nil {
b.Fatal(err)
}
seed := uint64(time.Now().UnixNano())
s := parsec.NewScanner(text)
root, _ := Y(s)
scope := root.(common.Scope)
nterms := scope["_nonterminals"].(common.NTForms)
scope = BuildContext(scope, seed, "./bags", prodfile)
b.ResetTimer()
out := 0
for i := 0; i < b.N; i++ {
scope = scope.RebuildContext()
if val, ok := EvalForms("root", scope, nterms["s"]).(string); !ok {
b.Fatalf("not string `%v`\n", val)
} else {
out += len(val)
}
}
b.SetBytes(int64(float64(out) / float64(b.N)))
}
示例14: BenchmarkAccessorSetReflection
// BenchmarkAccessorSetReflection provides a baseline for accessor performance
func BenchmarkAccessorSetReflection(b *testing.B) {
obj := &InternalObject{
InternalTypeMeta{
Namespace: "bar",
Name: "foo",
GenerateName: "prefix",
UID: "uid",
APIVersion: "a",
Kind: "b",
ResourceVersion: "1",
SelfLink: "some/place/only/we/know",
Labels: map[string]string{"foo": "bar"},
Annotations: map[string]string{"x": "y"},
},
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
acc, err := meta.Accessor(obj)
if err != nil {
b.Fatal(err)
}
acc.SetNamespace("something")
}
b.StopTimer()
}
示例15: benchmarkIterOnBatch
func benchmarkIterOnBatch(b *testing.B, writes int) {
stopper := stop.NewStopper()
defer stopper.Stop()
engine := createTestEngine(stopper)
for i := 0; i < writes; i++ {
if err := engine.Put(makeKey(i), []byte(strconv.Itoa(i))); err != nil {
b.Fatal(err)
}
}
batch := engine.NewBatch()
defer batch.Close()
for i := 0; i < writes; i++ {
if err := batch.Clear(makeKey(i)); err != nil {
b.Fatal(err)
}
}
r := rand.New(rand.NewSource(5))
b.ResetTimer()
for i := 0; i < b.N; i++ {
key := makeKey(r.Intn(writes))
iter := batch.NewIterator(true)
iter.Seek(key)
iter.Close()
}
}