Skip to content

Commit

Permalink
Changed benchmark to incl microseconds.
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Wulff committed Dec 10, 2024
1 parent 71b3daa commit c8043e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions internal/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package internal
import "time"

type BenchmarkResult struct {
TotalTimeInMs int64
Start int64
totalTime int64
start int64
}

func (b *BenchmarkResult) StartTimer() {
b.Start = time.Now().UnixMilli()
b.start = time.Now().UnixMicro()
}

func (b *BenchmarkResult) StopTimer() {
b.TotalTimeInMs = time.Now().UnixMilli() - b.Start
b.totalTime = time.Now().UnixMicro() - b.start
}

func (b BenchmarkResult) GetTotalTimeInMs() int64 {
return b.TotalTimeInMs
func (b BenchmarkResult) GetTotalTime() float64 {
return float64(b.totalTime) / 1000
}
8 changes: 4 additions & 4 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ func Run() {
w := tabwriter.NewWriter(os.Stdout, 0, 4, 4, ' ', 0)
fmt.Fprintln(w, "\nDay\tPart\tTime (ms)")

var sum int64 = 0
var sum float64 = 0.0
for _, p := range plugins {
sum += p.Benchmark.GetTotalTimeInMs()
sum += p.Benchmark.GetTotalTime()
// @TODO: would be nice to join day & parts in a single row, but for now it's already nice they're alphabetically sorted
fmt.Fprintf(w, "%s\t%s\t%d\n", p.Args.Day, p.Args.Part, p.Benchmark.GetTotalTimeInMs())
fmt.Fprintf(w, "%s\t%s\t%v\n", p.Args.Day, p.Args.Part, p.Benchmark.GetTotalTime())
}
w.Flush()

fmt.Printf("\nTotal time: %d ms\n", sum)
fmt.Printf("\nTotal time: %v ms\n", sum)
}

0 comments on commit c8043e5

Please sign in to comment.