From 9fec648bc8240c4031d547c8c677b5f9ec18d15a Mon Sep 17 00:00:00 2001 From: rjianu Date: Wed, 12 Jul 2023 15:32:29 +0300 Subject: [PATCH] feat: Add benchmark tests --- .gitignore | 1 + benchresults.txt | 6 ++++++ csv_test.go | 4 ++-- main_test.go | 16 ++++++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 benchresults.txt diff --git a/.gitignore b/.gitignore index e69de29..b26bca2 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +benchmark \ No newline at end of file diff --git a/benchresults.txt b/benchresults.txt new file mode 100644 index 0000000..7403d5f --- /dev/null +++ b/benchresults.txt @@ -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 diff --git a/csv_test.go b/csv_test.go index c0d38a3..3324326 100644 --- a/csv_test.go +++ b/csv_test.go @@ -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 diff --git a/main_test.go b/main_test.go index 4912772..5e91040 100644 --- a/main_test.go +++ b/main_test.go @@ -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) + } + } +}