- Change Abstraction, Application, and Variable to use private fields with getter methods - Return value types instead of pointers from constructors - Update all type switches to match value types instead of pointer types - Remove pointer equality optimizations (not applicable with immutable values) - Return empty set instead of nil from GetFreeVariables default case
45 lines
845 B
Go
45 lines
845 B
Go
package plugins
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"git.maximhutz.com/max/lambda/internal/statistics"
|
|
"git.maximhutz.com/max/lambda/pkg/interpreter"
|
|
)
|
|
|
|
// An observer, to track reduction performance.
|
|
type Statistics struct {
|
|
start time.Time
|
|
steps uint64
|
|
}
|
|
|
|
// Create a new reduction performance Statistics.
|
|
func NewStatistics(r interpreter.Interpreter) *Statistics {
|
|
plugin := &Statistics{}
|
|
r.On(interpreter.StartEvent, plugin.Start)
|
|
r.On(interpreter.StepEvent, plugin.Step)
|
|
r.On(interpreter.StopEvent, plugin.Stop)
|
|
|
|
return plugin
|
|
}
|
|
|
|
func (t *Statistics) Start() {
|
|
t.start = time.Now()
|
|
t.steps = 0
|
|
}
|
|
|
|
func (t *Statistics) Step() {
|
|
t.steps++
|
|
}
|
|
|
|
func (t *Statistics) Stop() {
|
|
results := statistics.Results{
|
|
StepsTaken: t.steps,
|
|
TimeElapsed: uint64(time.Since(t.start).Milliseconds()),
|
|
}
|
|
|
|
fmt.Fprint(os.Stderr, results.String())
|
|
}
|