diff options
author | Damian Gryski <[email protected]> | 2023-04-09 09:41:15 -0700 |
---|---|---|
committer | Ron Evans <[email protected]> | 2023-04-11 12:16:25 +0200 |
commit | e00a2395d9e30b92c2e5050831398647a4c95e5e (patch) | |
tree | 39e0524be2e4dd198e88b52821f2d9b5cf965ee4 /src | |
parent | 42175496eb8e3e259f9f80a9b688145957185967 (diff) | |
download | tinygo-e00a2395d9e30b92c2e5050831398647a4c95e5e.tar.gz tinygo-e00a2395d9e30b92c2e5050831398647a4c95e5e.zip |
testing: fix benchmark logging output
Diffstat (limited to 'src')
-rw-r--r-- | src/testing/benchmark.go | 15 | ||||
-rw-r--r-- | src/testing/testing.go | 4 |
2 files changed, 16 insertions, 3 deletions
diff --git a/src/testing/benchmark.go b/src/testing/benchmark.go index 5a3532606..b7bd106bc 100644 --- a/src/testing/benchmark.go +++ b/src/testing/benchmark.go @@ -11,6 +11,7 @@ import ( "fmt" "io" "math" + "os" "runtime" "strconv" "strings" @@ -378,7 +379,8 @@ func runBenchmarks(matchString func(pat, str string) (bool, error), benchmarks [ } main := &B{ common: common{ - name: "Main", + output: &logger{}, + name: "Main", }, benchTime: benchTime, benchFunc: func(b *B) { @@ -416,6 +418,12 @@ func (b *B) processBench(ctx *benchContext) { results += "\t" + r.MemString() } fmt.Println(results) + + // Print any benchmark output + if b.output.Len() > 0 { + fmt.Printf("--- BENCH: %s\n", benchName) + b.output.WriteTo(os.Stdout) + } } } } @@ -436,8 +444,9 @@ func (b *B) Run(name string, f func(b *B)) bool { b.hasSub = true sub := &B{ common: common{ - name: benchName, - level: b.level + 1, + output: &logger{}, + name: benchName, + level: b.level + 1, }, benchFunc: f, benchTime: b.benchTime, diff --git a/src/testing/testing.go b/src/testing/testing.go index 5c81a312e..7f01f1311 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -95,6 +95,10 @@ func (l *logger) WriteTo(w io.Writer) (int64, error) { } +func (l *logger) Len() int { + return l.b.Len() +} + // Short reports whether the -test.short flag is set. func Short() bool { return flagShort |