func BenchmarkWalkPanic(b *testing.B) {
	var list error
	for i := 1; i <= listLen; i++ {
		list = errors.Append(list, fmt.Errorf("number %v", i))
	}
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		func() {
			defer func() {
				if e := recover(); e != nil {
					panic(e)
				}
			}()
			n := attentionSpan
			i := 0
			errors.Walk(list, func(e error) {
				_ = e
				i++
				if i >= n {
					panic(nil)
				}
			})
		}()
	}
}
示例#2
0
func ExampleAppendCall() {
	buf, err := ReinventTheIOUtil("errorlist.go")
	if err != nil {
		command := filepath.Base(os.Args[0])
		errors.Walk(err, func(e error) {
			fmt.Fprintf(os.Stderr, "%s, Error: %s\n", command, e)
		})
	}
	_ = buf // do something magical with it!
}
func BenchmarkWalkIgnore(b *testing.B) {
	var list error
	for i := 1; i <= listLen; i++ {
		list = errors.Append(list, fmt.Errorf("number %v", i))
	}
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		n := attentionSpan
		i := 0
		errors.Walk(list, func(e error) {
			i++
			if i > n {
				return
			}
			_ = e
		})
	}
}