go: update SaveStats func to take ([]Stats, fName)
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-06-20 02:49:24 +02:00
parent a80b6660e5
commit a121a1eb4b
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D

@ -5,10 +5,8 @@ package stats
import ( import (
"encoding/json" "encoding/json"
"fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"os"
) )
// BenchRound holds the iteration couter value and Results of size 'maxFES'. // BenchRound holds the iteration couter value and Results of size 'maxFES'.
@ -51,15 +49,16 @@ func GetStats(algo string, dimens int, benchFuncStats []FuncStats, iterations, g
return s return s
} }
func SaveStats(stats Stats) { func SaveStats(stats []Stats, fName string) {
prefix := "res/stats/"
ext := ".json"
if j, err := json.MarshalIndent(stats, "", " "); err != nil { if j, err := json.MarshalIndent(stats, "", " "); err != nil {
log.Fatal(err) log.Fatal(err)
} else { } else {
fmt.Fprintln(os.Stderr, j) log.Println("saving json stats to:", prefix+fName+ext)
log.Println("saving json stats to: test.json") if err = ioutil.WriteFile(prefix+fName+ext, j, 0o600); err != nil {
if err = ioutil.WriteFile("test.json", j, 0o600); err != nil {
log.Println("error saving stats to file:", err) log.Println("error saving stats to file:", err)
} }
} }