-
Notifications
You must be signed in to change notification settings - Fork 16
/
go_test_bench.cli.txt
93 lines (68 loc) · 5.65 KB
/
go_test_bench.cli.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
GO_TEST_BENCH
VERSION ==> #See Go language
RELATED DOCUMENTATION ==> #See Go language
TESTING ==> #See go_test documentation
/=+===============================+=\
/ : : \
)==: CLI :==(
\ :_______________________________: /
\=+===============================+=/
go test
-bench REGEXP #Only run benchmarks whose "BenchmarkNAME" partially matches REGEXP
#"" means ".*"
#Unless set, no benchmarks is run
-benchtime DURATION #How long to run benchmark (def: "1s")
-count NUM #How many times to repeat benchmarks (def: 1)
/=+===============================+=\
/ : : \
)==: PROGRAMMATIC :==(
\ :_______________________________: /
\=+===============================+=/
testing.Benchmark
(FUNC(*testing.B))
->BENCHMARK_RESULT #Run a benchmark manually without go test
testing.Init() #To call inside manual Benchmark FUNC() if want to allow using test CLI flags, or retrieve their value
#without using go test
BENCHMARK_RESULT.N #Like B.N
BENCHMARK_RESULT.T #Time.DURATION taken
BENCHMARK_RESULT.NsPerOp()->INT64 #Ns per iteration
BENCHMARK_RESULT.Bytes #INT64. Average bytes per iteration, set by B.SetBytes()
BENCHMARK_RESULT.Extra #MAP[STR]FLOAT64 of metrics through B.ReportMetric()
BENCHMARK_RESULT.String()->STR #"{N} [NUM ns/op] [NUM MB/s] [METRIC UNIT]..."
/=+===============================+=\
/ : : \
)==: BENCHMARKS :==(
\ :_______________________________: /
\=+===============================+=/
BenchmarkNAME(*testing.B) #Benchmark function
#Prints GOOS, GOARCH, MODULE_PATH, NAME
#Runs for one minute then prints:
# - number of iterations
# - average iteration speed
# - number of goroutines
#Can also use test assertions, and behave like a test function
testing.B #Benchmark utilities
B.* #All T.* are available
# - exception: logs are always printed
testing.TB #INTERFACE with methods common to T and B
B.N #Max iteration INT to run in loops
#For example: for i := 0; i < b.N; i++ {...}
B.ResetTimer() #To do after setup code, so the setup does not add to the benchmark
B.StopTimer() #Pause timer
B.StartTimer() #Re-start timer
B.ReportAllocs() #Like -test.benchmem, but only for this function
B.SetBytes(INT64) #Report that the current test read or write INT64 bytes by current iteration, to benchmark I/O
#This will be printed as MB/s in the test output.
B.ReportMetric(FLOAT64, "UNIT") #Report "FLOAT64 UNIT" in test output
#Must be called only once per FUNC
#Goal is to do own measuring and report it
#If "UNIT" is already reported by go test, override it
B.SetParallelism(INT) #Increase the number of max goroutines to INT * GOMAXPROCS
B.RunParallel(FUNC(*PB)) #Creates GOMAXPROCS goroutines and run all goroutines in parallel.
#I.e. benchmarks in parallel instead of serially
#Blocks until complete
PB.Next()->BOOL #Mark start of a new iteration
#Returns false if last iteration.
#To use in: for PB.Next() {...}