Skip to content

Commit

Permalink
Simplify benchmark and add comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimafisk committed May 14, 2020
1 parent 8e88fe5 commit 5c219f2
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions cmd/build/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,30 @@ package build

import (
"fmt"
"sync"
"time"
)

var doOnce sync.Once

var benchmarkFlag bool = false
var benchmarkFlag bool
var messages []string
var allElapsed []time.Duration
var elapsed []time.Duration

// Benchmark records time for individual build processes.
func Benchmark(start time.Time, message string, BenchmarkFlags ...bool) {

elapsed := time.Since(start)
allElapsed = append(allElapsed, elapsed)
elapsed = append(elapsed, time.Since(start))
messages = append(messages, message)

// Get length of variadic args (used to mimic optional parameters).
numFlags := len(BenchmarkFlags)
// If the --benchmark flag is true.
if numFlags == 1 && BenchmarkFlags[0] {
// Show time spent on each stage of build process.
for i, m := range messages {
fmt.Printf("\n%s took %s\n", m, allElapsed[i])
fmt.Printf("\n%s took %s\n", m, elapsed[i])
}
} else if numFlags == 1 {
fmt.Printf("\n%s took %s\n", message, elapsed)
// If the --benchmark flag is false, just print overall build time.
fmt.Printf("\n%s took %s\n", message, elapsed[0])
}

}

0 comments on commit 5c219f2

Please sign in to comment.