Skip to content

Commit

Permalink
apply benchmark suggestions by lu4p
Browse files Browse the repository at this point in the history
I had these ready for the PR, but forgot to push before merging.
  • Loading branch information
mvdan committed Jan 24, 2022
1 parent f497821 commit d49c244
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ func BenchmarkBuild(b *testing.B) {
qt.Assert(b, err, qt.IsNil)

// We collect extra metrics.
var userTime, systemTime int64

var cachedTime int64
var cachedTime, userTime, systemTime int64

outputBin := filepath.Join(b.TempDir(), "output")
sourceDir := filepath.Join(b.TempDir(), "src")
Expand Down Expand Up @@ -109,9 +107,9 @@ func BenchmarkBuild(b *testing.B) {
qt.Assert(b, rxBuiltRuntime.Match(out), qt.IsFalse)
qt.Assert(b, rxBuiltMain.Match(out), qt.IsTrue)

cachedTime += time.Since(cachedStart).Nanoseconds()
userTime += int64(cmd.ProcessState.UserTime())
systemTime += int64(cmd.ProcessState.SystemTime())
cachedTime += time.Since(cachedStart).Nanoseconds()
}
b.ReportMetric(float64(cachedTime)/float64(b.N), "cached-ns/op")
b.ReportMetric(float64(userTime)/float64(b.N), "user-ns/op")
Expand Down

0 comments on commit d49c244

Please sign in to comment.