本文整理汇总了Golang中testing.B.Errorf方法的典型用法代码示例。如果您正苦于以下问题:Golang B.Errorf方法的具体用法?Golang B.Errorf怎么用?Golang B.Errorf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testing.B
的用法示例。
在下文中一共展示了B.Errorf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: benchMatch
func benchMatch(b *testing.B, re regexper, dos bool) {
patterns := []string{`Hello World!`, `Hello Friend!`, `Hello 友達!`}
for _, pat := range patterns {
var rv bool
if dos {
rv = re.MatchString(pat)
} else {
rv = re.Match([]byte(pat))
}
if !rv {
b.Errorf("Expected to match, failed")
return
}
}
patterns = []string{`Goodbye World!`, `Hell no!`, `HelloWorld!`}
for _, pat := range patterns {
var rv bool
if dos {
rv = re.MatchString(pat)
} else {
rv = re.Match([]byte(pat))
}
if rv {
b.Errorf("Expected to NOT match, matched")
return
}
}
}
示例2: BenchmarkContention
func BenchmarkContention(b *testing.B) {
b.StopTimer()
var procs = runtime.NumCPU()
var origProcs = runtime.GOMAXPROCS(procs)
var db = NewLogeDB(NewMemStore())
db.CreateType(NewTypeDef("counters", 1, &TestCounter{}))
db.Transact(func(t *Transaction) {
t.Set("counters", "contended", &TestCounter{Value: 0})
}, 0)
b.StartTimer()
var group sync.WaitGroup
for i := 0; i < procs; i++ {
group.Add(1)
go LoopIncrement(db, "contended", &group, b.N)
}
group.Wait()
b.StopTimer()
db.Transact(func(t *Transaction) {
var target = b.N * procs
var counter = t.Read("counters", "contended").(*TestCounter)
if counter.Value != uint32(target) {
b.Errorf("Wrong count for counter: %d / %d",
counter.Value, target)
}
}, 0)
runtime.GOMAXPROCS(origProcs)
}
示例3: Benchmark__PubSubTwoConns
func Benchmark__PubSubTwoConns(b *testing.B) {
b.StopTimer()
s := runBenchServer()
c := createClientConn(b, "localhost", PERF_PORT)
doDefaultConnect(b, c)
bw := bufio.NewWriterSize(c, defaultSendBufSize)
c2 := createClientConn(b, "localhost", PERF_PORT)
doDefaultConnect(b, c2)
sendProto(b, c2, "SUB foo 1\r\n")
sendOp := []byte(fmt.Sprintf("PUB foo 2\r\nok\r\n"))
ch := make(chan bool)
expected := len("MSG foo 1 2\r\nok\r\n") * b.N
go drainConnection(b, c2, ch, expected)
b.StartTimer()
for i := 0; i < b.N; i++ {
bw.Write(sendOp)
}
err := bw.Flush()
if err != nil {
b.Errorf("Received error on FLUSH write: %v\n", err)
}
// Wait for connection to be drained
<-ch
b.StopTimer()
c.Close()
c2.Close()
s.Shutdown()
}
示例4: BenchmarkServerFakeConnWithKeepAliveLite
// same as above, but representing the most simple possible request
// and handler. Notably: the handler does not call rw.Header().
func BenchmarkServerFakeConnWithKeepAliveLite(b *testing.B) {
req := []byte(strings.Replace(`GET / HTTP/1.1
Host: golang.org
`, "\n", "\r\n", -1))
res := []byte("Hello world!\n")
conn := &rwTestConn{
Reader: &repeatReader{content: req, count: b.N},
Writer: ioutil.Discard,
closec: make(chan bool, 1),
}
handled := 0
handler := HandlerFunc(func(rw ResponseWriter, r *Request) {
handled++
rw.Write(res)
})
ln := &oneConnListener{conn: conn}
go Serve(ln, handler)
<-conn.closec
if b.N != handled {
b.Errorf("b.N=%d but handled %d", b.N, handled)
}
}
示例5: 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)
}
示例6: BenchmarkSigVerify
// BenchmarkSigVerify benchmarks how long it takes the secp256k1 curve to
// verify signatures.
func BenchmarkSigVerify(b *testing.B) {
b.StopTimer()
// Randomly generated keypair.
// Private key: 9e0699c91ca1e3b7e3c9ba71eb71c89890872be97576010fe593fbf3fd57e66d
pubKey := PublicKey{
Curve: S256(),
X: fromHex("d2e670a19c6d753d1a6d8b20bd045df8a08fb162cf508956c31268c6d81ffdab"),
Y: fromHex("ab65528eefbb8057aa85d597258a3fbd481a24633bc9b47a9aa045c91371de52"),
}
// Double sha256 of []byte{0x01, 0x02, 0x03, 0x04}
msgHash := fromHex("8de472e2399610baaa7f84840547cd409434e31f5d3bd71e4d947f283874f9c0")
sig := Signature{
R: fromHex("fef45d2892953aa5bbcdb057b5e98b208f1617a7498af7eb765574e29b5d9c2c"),
S: fromHex("d47563f52aac6b04b55de236b7c515eb9311757db01e02cff079c3ca6efb063f"),
}
if !sig.Verify(msgHash.Bytes(), &pubKey) {
b.Errorf("Signature failed to verify")
return
}
b.StartTimer()
for i := 0; i < b.N; i++ {
sig.Verify(msgHash.Bytes(), &pubKey)
}
}
示例7: benchmarkStoreRead
func benchmarkStoreRead(b *testing.B, store data.Store) {
var n = 1000
benchmarkStoreInsert(b, store, n)
b.ResetTimer()
var users = store.Collection("users")
for k := 0; k < b.N; k++ {
var i = rand.Intn(n - 1)
var name = fmt.Sprintf("user%d", i+1)
var email = fmt.Sprintf("%[email protected]", name)
var usr User
var err = users.Find(q.Or{
q.M{"id": name},
q.M{"name": name},
q.M{"email": name},
}).One(&usr)
if err != nil {
b.Errorf("find one failed with %v", err)
b.FailNow()
}
err = users.Find(q.Or{
q.M{"id": email},
q.M{"name": email},
q.M{"email": email},
}).One(&usr)
if err != nil {
b.Errorf("find one failed with %v", err)
b.FailNow()
}
}
}
示例8: BenchmarkRoundtripTxt
func BenchmarkRoundtripTxt(b *testing.B) {
b.StopTimer()
sample, min, max := initRoundtripBenchmarks()
sampleString := string(sample)
b.ReportAllocs()
tb := (*TB)(b)
db := tb.checkDB(sql.Open("mysql", dsn))
defer db.Close()
b.StartTimer()
var result string
for i := 0; i < b.N; i++ {
length := min + i
if length > max {
length = max
}
test := sampleString[0:length]
rows := tb.checkRows(db.Query(`SELECT "` + test + `"`))
if !rows.Next() {
rows.Close()
b.Fatalf("crashed")
}
err := rows.Scan(&result)
if err != nil {
rows.Close()
b.Fatalf("crashed")
}
if result != test {
rows.Close()
b.Errorf("mismatch")
}
rows.Close()
}
}
示例9: BenchmarkRoundtripBin
func BenchmarkRoundtripBin(b *testing.B) {
b.StopTimer()
sample, min, max := initRoundtripBenchmarks()
b.ReportAllocs()
tb := (*TB)(b)
db := tb.checkDB(sql.Open("mysql", dsn))
defer db.Close()
stmt := tb.checkStmt(db.Prepare("SELECT ?"))
defer stmt.Close()
b.StartTimer()
var result sql.RawBytes
for i := 0; i < b.N; i++ {
length := min + i
if length > max {
length = max
}
test := sample[0:length]
rows := tb.checkRows(stmt.Query(test))
if !rows.Next() {
rows.Close()
b.Fatalf("crashed")
}
err := rows.Scan(&result)
if err != nil {
rows.Close()
b.Fatalf("crashed")
}
if !bytes.Equal(result, test) {
rows.Close()
b.Errorf("mismatch")
}
rows.Close()
}
}
示例10: benchmarkScanner
func benchmarkScanner(b *testing.B, scanner osm.Scanner) (int, int, int) {
var (
nodes int
ways int
relations int
)
for scanner.Scan() {
e := scanner.Element()
if e.Node != nil {
nodes++
}
if e.Way != nil {
ways++
}
if e.Relation != nil {
relations++
}
}
if err := scanner.Err(); err != nil {
b.Errorf("scanner returned error: %v", err)
}
return nodes, ways, relations
}
示例11: BenchmarkRoundTrip
func BenchmarkRoundTrip(b *testing.B) {
r1, s1 := Pipe()
r2, s2 := Pipe()
go func() {
var m BenchMessage
for {
if err := r1.Receive(&m); err != nil {
b.Fatalf("Error receiving BenchMessage: %s", err)
}
if err := s2.Send(&m); err != nil {
b.Fatalf("Error sending BenchMessage: %s", err)
}
}
}()
var sm BenchMessage
var rm BenchMessage
for i := 0; i < b.N; i++ {
sm.I = i
if err := s1.Send(&sm); err != nil {
b.Fatalf("Error sending bench message: %s", err)
}
if err := r2.Receive(&rm); err != nil {
b.Fatalf("Error receiving bench message: %s", err)
}
if rm.I != sm.I {
b.Errorf("Wrong int received: %d, expecting: %d", rm.I, sm.I)
}
}
}
示例12: BenchmarkClientFutureParallel
func BenchmarkClientFutureParallel(b *testing.B) {
var err error
client, err := Connect(server, opts)
if err != nil {
b.Errorf("No connection available")
}
_, err = client.Replace(spaceNo, tuple1)
if err != nil {
b.Errorf("No connection available")
}
b.RunParallel(func(pb *testing.PB) {
exit := false
for !exit {
var fs [N]*Future
var j int
for j = 0; j < N && pb.Next(); j++ {
fs[j] = client.SelectAsync(spaceNo, indexNo, offset, limit, iterator, key)
}
exit = j < N
for j > 0 {
j--
_, err = fs[j].Get()
if err != nil {
b.Error(err)
}
}
}
})
}
示例13: BenchmarkBatch200RandomWritesParallel10
func BenchmarkBatch200RandomWritesParallel10(b *testing.B) {
var term Term
var data []map[string]interface{}
b.SetParallelism(10)
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
for is := 0; is < 200; is++ {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
cid := map[string]interface{}{
"customer_id": strconv.FormatInt(r.Int63(), 10),
}
data = append(data, cid)
}
// Insert the new item into the database
term = DB("benchmarks").Table("benchmarks").Insert(data)
// Insert the new item into the database
_, err := term.RunWrite(session, RunOpts{
MinBatchRows: 200,
MaxBatchRows: 200,
})
if err != nil {
b.Errorf("insert failed [%s] ", err)
}
}
})
}
示例14: BenchmarkSequentialSoftWritesParallel10
func BenchmarkSequentialSoftWritesParallel10(b *testing.B) {
var mu sync.Mutex
si := 0
// p*GOMAXPROCS
b.SetParallelism(10)
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
mu.Lock()
si++
mu.Unlock()
data := map[string]interface{}{
"customer_id": si,
}
opts := InsertOpts{Durability: "soft"}
// Insert the new item into the database
_, err := Table("benchmarks").Insert(data, opts).RunWrite(session)
if err != nil {
b.Errorf("insert failed [%s] ", err)
return
}
}
})
}
示例15: Benchmark10kGlobal
func Benchmark10kGlobal(b *testing.B) {
var remote []scanner.File
for i := 0; i < 10000; i++ {
remote = append(remote, scanner.File{Name: fmt.Sprintf("file%d", i), Version: 1000})
}
m := NewSet()
m.Replace(cid.LocalID+1, remote)
var local []scanner.File
for i := 0; i < 2000; i++ {
local = append(local, scanner.File{Name: fmt.Sprintf("file%d", i), Version: 1000})
}
for i := 2000; i < 10000; i++ {
local = append(local, scanner.File{Name: fmt.Sprintf("file%d", i), Version: 980})
}
m.ReplaceWithDelete(cid.LocalID, local)
b.ResetTimer()
for i := 0; i < b.N; i++ {
fs := m.Global()
if l := len(fs); l != 10000 {
b.Errorf("wrong length %d != 10k", l)
}
}
}