29 lines
812 B
Go
29 lines
812 B
Go
// Package "statistics" provides a way to observer reduction speed during
|
|
// execution.
|
|
package statistics
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// Statistics for a specific reduction.
|
|
type Results struct {
|
|
StepsTaken uint64 // Number of steps taken during execution.
|
|
TimeElapsed uint64 // The time (ms) taken for execution to complete.
|
|
}
|
|
|
|
// Returns the average number of operations per second of the execution.
|
|
func (r Results) OpsPerSecond() float32 {
|
|
return float32(r.StepsTaken) / (float32(r.TimeElapsed) / 1000)
|
|
}
|
|
|
|
// Format the results as a string.
|
|
func (r Results) String() string {
|
|
builder := strings.Builder{}
|
|
fmt.Fprintln(&builder, "Time Spent:", r.TimeElapsed, "ms")
|
|
fmt.Fprintln(&builder, "Steps:", r.StepsTaken)
|
|
fmt.Fprintln(&builder, "Speed:", r.OpsPerSecond(), "ops")
|
|
return builder.String()
|
|
}
|