Documentation ¶
Index ¶
- Variables
- func CostWith(fn func()) (dur time.Duration)
- func Count(n int) <-chan int
- func FuncSprint(args ...interface{}) string
- func PrintMemStats()
- func Range(min, max int) int
- func RangeBytes(min, max int) []byte
- func RangeDur(min, max time.Duration) time.Duration
- func RangeString(min, max int) string
- func SliceOf(args ...interface{}) []interface{}
- func TestFuncWith(fn interface{}) *xtest
- func Tick(args ...interface{}) <-chan time.Time
- func TimeoutWith(dur time.Duration, fn func()) error
- func Try(fn func()) (e error)
- func Wrap(fn interface{}) func(...interface{}) func(...interface{}) (err error)
- type B
- type BenchmarkResult
Constants ¶
This section is empty.
Variables ¶
var ( ErrXTest = xerror.New("xtest error") ErrParamIsNil = ErrXTest.New("the parameter is nil") ErrFuncTimeout = ErrXTest.New("the func is timeout") ErrParamTypeNotFunc = ErrXTest.New("the type of the parameters is not func") ErrDurZero = ErrXTest.New("the duration time must more than zero") ErrInputParamsNotMatch = ErrXTest.New("the input params of func is not match") ErrInputOutputParamsNotMatch = ErrXTest.New("the input num and output num of the callback func is not match") ErrFuncOutputTypeNotMatch = ErrXTest.New("the output type of the callback func is not match") ErrForeachParameterNil = ErrXTest.New("the parameter of [Foreach] must not be nil") )
Functions ¶
func FuncSprint ¶ added in v0.1.2
func FuncSprint(args ...interface{}) string
func PrintMemStats ¶ added in v0.1.8
func PrintMemStats()
func TestFuncWith ¶
func TestFuncWith(fn interface{}) *xtest
func TimeoutWith ¶
Types ¶
type B ¶ added in v0.1.8
type B struct { N int // contains filtered or unexported fields }
func (*B) ReportAllocs ¶ added in v0.1.8
func (b *B) ReportAllocs()
ReportAllocs enables malloc statistics for this benchmark. It is equivalent to setting -test.benchmem, but it only affects the benchmark function that calls ReportAllocs.
func (*B) ResetTimer ¶ added in v0.1.8
func (b *B) ResetTimer()
ResetTimer zeroes the elapsed benchmark time and memory allocation counters and deletes user-reported metrics. It does not affect whether the timer is running.
func (*B) SetBytes ¶ added in v0.1.8
SetBytes records the number of bytes processed in a single operation. If this is called, the benchmark will report ns/op and MB/s.
func (*B) StartTimer ¶ added in v0.1.8
func (b *B) StartTimer()
StartTimer starts timing a test. This function is called automatically before a benchmark starts, but it can also be used to resume timing after a call to StopTimer.
type BenchmarkResult ¶ added in v0.1.8
type BenchmarkResult struct { N int // The number of iterations. T time.Duration // The total time taken. Bytes int64 // Bytes processed in one iteration. MemAllocs uint64 // The total number of memory allocations. MemBytes uint64 // The total number of bytes allocated. // Extra records additional metrics reported by ReportMetric. Extra map[string]float64 }
BenchmarkResult contains the results of a benchmark run.
func Benchmark ¶ added in v0.1.8
func Benchmark(n int, f func(b *B)) BenchmarkResult
Benchmark benchmarks a single function. It is useful for creating custom benchmarks that do not use the "go test" command.
If f depends on testing flags, then Init must be used to register those flags before calling Benchmark and before calling flag.Parse.
If f calls Run, the result will be an estimate of running all its subbenchmarks that don't call Run in sequence in a single benchmark.
func (BenchmarkResult) AllocedBytesPerOp ¶ added in v0.1.8
func (r BenchmarkResult) AllocedBytesPerOp() int64
AllocedBytesPerOp returns the "B/op" metric, which is calculated as r.MemBytes / r.N.
func (BenchmarkResult) AllocsPerOp ¶ added in v0.1.8
func (r BenchmarkResult) AllocsPerOp() int64
AllocsPerOp returns the "allocs/op" metric, which is calculated as r.MemAllocs / r.N.
func (BenchmarkResult) MemString ¶ added in v0.1.8
func (r BenchmarkResult) MemString() string
MemString returns r.AllocedBytesPerOp and r.AllocsPerOp in the same format as 'go test'.
func (BenchmarkResult) NsPerOp ¶ added in v0.1.8
func (r BenchmarkResult) NsPerOp() int64
NsPerOp returns the "ns/op" metric.
func (BenchmarkResult) String ¶ added in v0.1.8
func (r BenchmarkResult) String() string
String returns a summary of the benchmark results. It follows the benchmark result line format from https://golang.org/design/14313-benchmark-format, not including the benchmark name. Extra metrics override built-in metrics of the same name. String does not include allocs/op or B/op, since those are reported by MemString.