Skip to content

Commit

Permalink
Rename timers more appropriately
Browse files Browse the repository at this point in the history
  • Loading branch information
Winston Ho committed Oct 18, 2022
1 parent f236919 commit 7e3ad4e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ func runBenchmark(ctx context.Context, cmdToBenchmark string) (*benchmarkResult,

fmt.Print("Initial time measurement")
for i := int64(0); i < runs; i++ {
processBenchmark.Reset()
if err := processBenchmark.Run(ctx, cmdParts[0], cmdParts[1:]...); err != nil {
processTimer.Reset()
if err := processTimer.Run(ctx, cmdParts[0], cmdParts[1:]...); err != nil {
return nil, err
}
totalUserTime += processBenchmark.GetUserTime()
totalKernelTime += processBenchmark.GetKernelTime()
elapsedRuns[i] = processBenchmark.GetRealTime()
totalUserTime += processTimer.GetUserTime()
totalKernelTime += processTimer.GetKernelTime()
elapsedRuns[i] = processTimer.GetRealTime()

// Calculate current estimate and ETA
currentEstimate = (currentEstimate*i + elapsedRuns[i]) / (i + 1)
Expand Down
4 changes: 2 additions & 2 deletions measure.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package main

import "context"

type benchmark interface {
type timer interface {
GetUserTime() int64
GetKernelTime() int64
GetRealTime() int64
Run(context.Context, string, ...string) error
Reset()
}

var processBenchmark benchmark
var processTimer timer
14 changes: 7 additions & 7 deletions measure_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"golang.org/x/sys/windows"
)

type windowsProcess struct {
type windowsTimer struct {
userTime int64
kernelTime int64
realTime int64
Expand All @@ -36,10 +36,10 @@ type JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION struct {
}

func init() {
processBenchmark = new(windowsProcess)
processTimer = new(windowsTimer)
}

func (w *windowsProcess) Run(ctx context.Context, name string, arg ...string) error {
func (w *windowsTimer) Run(ctx context.Context, name string, arg ...string) error {
cmd := exec.CommandContext(ctx, name, arg...)
cmd.SysProcAttr = &syscall.SysProcAttr{
CreationFlags: windows.CREATE_NEW_PROCESS_GROUP | windows.CREATE_SUSPENDED,
Expand Down Expand Up @@ -88,13 +88,13 @@ func (w *windowsProcess) Run(ctx context.Context, name string, arg ...string) er
return nil
}

func (w *windowsProcess) GetUserTime() int64 { return w.userTime * HundredNSTicks }
func (w *windowsTimer) GetUserTime() int64 { return w.userTime * HundredNSTicks }

func (w *windowsProcess) GetKernelTime() int64 { return w.kernelTime * HundredNSTicks }
func (w *windowsTimer) GetKernelTime() int64 { return w.kernelTime * HundredNSTicks }

func (w *windowsProcess) GetRealTime() int64 { return w.realTime }
func (w *windowsTimer) GetRealTime() int64 { return w.realTime }

func (w *windowsProcess) Reset() {
func (w *windowsTimer) Reset() {
w.userTime = 0
w.kernelTime = 0
w.realTime = 0
Expand Down

0 comments on commit 7e3ad4e

Please sign in to comment.