feat: observer pattern for statistics

This commit is contained in:
2025-12-29 00:51:50 -05:00
parent e9dc3fe171
commit c2b397a9f6
11 changed files with 165 additions and 70 deletions

View File

@@ -0,0 +1,23 @@
package statistics
import (
"fmt"
"strings"
)
type Results struct {
StepsTaken uint64 // Number of steps taken during execution.
TimeElapsed uint64 // The time (ms) taken for execution to complete.
}
func (r Results) OpsPerSecond() float32 {
return float32(r.StepsTaken) / (float32(r.TimeElapsed) / 1000)
}
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()
}