From ecf3ae90ff4741c91292825f3a73042146c84e9b Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Wed, 29 Nov 2017 21:47:00 +0000 Subject: [PATCH] add a benchmark for report unmarshalling --- report/benchmark_internal_test.go | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 report/benchmark_internal_test.go diff --git a/report/benchmark_internal_test.go b/report/benchmark_internal_test.go new file mode 100644 index 000000000..568372b50 --- /dev/null +++ b/report/benchmark_internal_test.go @@ -0,0 +1,40 @@ +package report + +import ( + "flag" + "os" + "path/filepath" + "testing" +) + +var ( + benchReportPath = flag.String("bench-report-path", "", "report file, or dir with files, to use for benchmarking (relative to this package)") +) + +func BenchmarkReportUnmarshal(b *testing.B) { + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + b.StopTimer() + b.StartTimer() + if err := readReportFiles(*benchReportPath); err != nil { + b.Fatal(err) + } + } +} + +func readReportFiles(path string) error { + return filepath.Walk(path, + func(p string, info os.FileInfo, err error) error { + if err != nil { + return err + } + if info.IsDir() { + return nil + } + if _, err := MakeFromFile(p); err != nil { + return err + } + return nil + }) +}