File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -6,11 +6,42 @@ package main
6
6
7
7
import (
8
8
"net/http"
9
+ "os"
10
+ "regexp"
9
11
"runtime"
12
+ "strings"
10
13
"testing"
11
14
)
12
15
16
+ var benchRe * regexp.Regexp
17
+
18
+ func isTested (name string ) bool {
19
+ if benchRe == nil {
20
+ // Get -test.bench flag value (not accessible via flag package)
21
+ bench := ""
22
+ for _ , arg := range os .Args {
23
+ if strings .HasPrefix (arg , "-test.bench=" ) {
24
+ // ignore the benchmark name after an underscore
25
+ bench = strings .SplitN (arg [12 :], "_" , 2 )[0 ]
26
+ break
27
+ }
28
+ }
29
+
30
+ // Compile RegExp to match Benchmark names
31
+ var err error
32
+ benchRe , err = regexp .Compile (bench )
33
+ if err != nil {
34
+ panic (err .Error ())
35
+ }
36
+ }
37
+ return benchRe .MatchString (name )
38
+ }
39
+
13
40
func calcMem (name string , load func ()) {
41
+ if ! isTested (name ) {
42
+ return
43
+ }
44
+
14
45
m := new (runtime.MemStats )
15
46
16
47
// before
You can’t perform that action at this time.
0 commit comments