Skip to content

Commit fe98f61

Browse files
committed
Only calculate memory of tested frameworks
1 parent e7166bc commit fe98f61

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

bench_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,42 @@ package main
66

77
import (
88
"net/http"
9+
"os"
10+
"regexp"
911
"runtime"
12+
"strings"
1013
"testing"
1114
)
1215

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+
1340
func calcMem(name string, load func()) {
41+
if !isTested(name) {
42+
return
43+
}
44+
1445
m := new(runtime.MemStats)
1546

1647
// before

0 commit comments

Comments
 (0)