go(stats): add functions for manipulating Stats
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-06-17 23:56:36 +02:00
parent e178ee3237
commit ed76cf865b
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D

View File

@ -3,6 +3,14 @@
package stats
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
)
type FuncStats struct {
BenchName string
Results []float64
@ -15,3 +23,38 @@ type Stats struct {
Iterations int
Generations int
}
func GetFuncStats(funcName string, results []float64) FuncStats {
f := FuncStats{
BenchName: funcName,
Results: results,
}
return f
}
func GetStats(algo string, dimens int, benchFuncStats []FuncStats, iterations, generations int) Stats {
s := Stats{
Algo: algo,
Dimens: dimens,
BenchFuncStats: benchFuncStats,
Iterations: iterations,
Generations: generations,
}
return s
}
func SaveStats(stats Stats) {
if j, err := json.MarshalIndent(stats, "", " "); err != nil {
log.Fatal(err)
} else {
fmt.Fprintln(os.Stderr, j)
log.Println("saving json stats to: test.json")
if err = ioutil.WriteFile("test.json", j, 0o600); err != nil {
log.Println("error saving stats to file:", err)
}
}
}