feat: Add benchmark tests

This commit is contained in:
rjianu
2023-07-12 15:32:29 +03:00
parent b1f95ed90c
commit 9fec648bc8
4 changed files with 25 additions and 2 deletions

1
.gitignore vendored
View File

@@ -0,0 +1 @@
benchmark

6
benchresults.txt Normal file
View File

@@ -0,0 +1,6 @@
goos: linux
goarch: amd64
pkg: github.com/Serares/coolStats
BenchmarkRun-16 10 326633135 ns/op
PASS
ok github.com/Serares/coolStats 3.594s

View File

@@ -45,8 +45,8 @@ func TestCSV2Float(t *testing.T) {
192.168.0.88,899,220
192.168.0.199,3054,226
192.168.0.100,4133,218
192.168.0.199,950,238
`
192.168.0.199,950,238`
testCases := []struct {
name string
col int

View File

@@ -3,7 +3,9 @@ package main
import (
"bytes"
"errors"
"io"
"os"
"path/filepath"
"testing"
)
@@ -65,3 +67,17 @@ func TestRun(t *testing.T) {
})
}
}
func BenchmarkRun(b *testing.B) {
filenames, err := filepath.Glob("./testdata/benchmark/*.csv")
if err != nil {
b.Fatal(err)
}
// reset the time before running the benchmark loop
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := run(filenames, "avg", 2, io.Discard); err != nil {
b.Error(err)
}
}
}