feat: added optional profiling
This commit is contained in:
@@ -3,11 +3,10 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime/pprof"
|
||||
"time"
|
||||
|
||||
"git.maximhutz.com/max/lambda/internal/cli"
|
||||
"git.maximhutz.com/max/lambda/internal/config"
|
||||
"git.maximhutz.com/max/lambda/internal/executer"
|
||||
"git.maximhutz.com/max/lambda/pkg/convert"
|
||||
"git.maximhutz.com/max/lambda/pkg/lambda"
|
||||
"git.maximhutz.com/max/lambda/pkg/saccharine"
|
||||
@@ -15,14 +14,6 @@ import (
|
||||
|
||||
// Run main application.
|
||||
func main() {
|
||||
f, err := os.Create("profile/cpu.prof")
|
||||
cli.HandleError(err)
|
||||
defer f.Close()
|
||||
|
||||
err = pprof.StartCPUProfile(f)
|
||||
cli.HandleError(err)
|
||||
defer pprof.StopCPUProfile()
|
||||
|
||||
options, err := config.FromArgs()
|
||||
cli.HandleError(err)
|
||||
|
||||
@@ -50,29 +41,10 @@ func main() {
|
||||
logger.Info("compiled lambda expression", "tree", lambda.Stringify(compiled))
|
||||
}
|
||||
|
||||
// Reduce expression.
|
||||
start := time.Now()
|
||||
|
||||
if options.Explanation {
|
||||
fmt.Println(lambda.Stringify(compiled))
|
||||
}
|
||||
|
||||
steps := 0
|
||||
|
||||
for lambda.ReduceOnce(&compiled) {
|
||||
if options.Verbose {
|
||||
logger.Info("reduction", "tree", lambda.Stringify(compiled))
|
||||
}
|
||||
if options.Explanation {
|
||||
fmt.Println(" =", lambda.Stringify(compiled))
|
||||
}
|
||||
steps++
|
||||
}
|
||||
|
||||
elapsed := time.Since(start).Milliseconds()
|
||||
executor := executer.New(options)
|
||||
results, err := executor.Run(&compiled)
|
||||
cli.HandleError(err)
|
||||
|
||||
fmt.Println(lambda.Stringify(compiled))
|
||||
fmt.Fprintln(os.Stderr, "Time Spent:", elapsed, "ms")
|
||||
fmt.Fprintln(os.Stderr, "Steps:", steps)
|
||||
fmt.Fprintln(os.Stderr, "Speed:", float32(steps)/(float32(elapsed)/1000), "ops")
|
||||
fmt.Fprint(os.Stderr, results.String())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user