Skip to content

Commit

Permalink
Support printing previous stats files
Browse files Browse the repository at this point in the history
  • Loading branch information
bhperry committed Aug 18, 2024
1 parent dd51a0d commit f711a8a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
3 changes: 2 additions & 1 deletion tools/benchmark/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type Config struct {

// Run executes the benchmark and calculates statistics about its performance
func (c Config) Run() (stats *Stats, err error) {
fmt.Printf("Benchmark %s\n", c.Name)

run := func() {
windowConfig := c.WindowConfig
if windowConfig.Title == "" {
Expand Down Expand Up @@ -74,7 +76,6 @@ func (c Config) Run() (stats *Stats, err error) {
}
}

fmt.Printf("Running benchmark: %s\n", c.Name)
opengl.Run(run)

return stats, err
Expand Down
35 changes: 34 additions & 1 deletion tools/cmd/bench.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"encoding/json"
"fmt"
"os"
"text/tabwriter"
Expand All @@ -11,7 +12,11 @@ import (

func init() {
benchRunCmd.Flags().StringP("output", "o", "", "Output path for statistics file")
benchCmd.AddCommand(benchListCmd, benchRunCmd)

benchStatsCmd.Flags().StringP("input", "i", "", "Input path for statistics file")
benchStatsCmd.MarkFlagRequired("input")

benchCmd.AddCommand(benchListCmd, benchRunCmd, benchStatsCmd)
}

var (
Expand Down Expand Up @@ -67,4 +72,32 @@ var (
}
},
}
benchStatsCmd = &cobra.Command{
Use: "stats -i [path/to/stats.json]",
Short: "Pretty print the contents of a stats file",
RunE: func(cmd *cobra.Command, args []string) error {
input, err := cmd.Flags().GetString("input")
if err != nil {
return err
}
cmd.SilenceUsage = true

bytes, err := os.ReadFile(input)
if err != nil {
return err
}

var benchStats benchmark.StatsCollection
if err := json.Unmarshal(bytes, &benchStats); err != nil {
return err
}

for _, stats := range benchStats {
fmt.Printf("Benchmark %s\n", stats.Name)
stats.Print()
}

return nil
},
}
)

0 comments on commit f711a8a

Please sign in to comment.