From 8dfddfbc1e19605cbf70645a0baea0bd5ad005d6 Mon Sep 17 00:00:00 2001 From: Ella Pietraroia Date: Tue, 11 Feb 2020 12:14:21 +1030 Subject: [PATCH] filter: benchmark: tidying code --- filter/filter_test.go | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/filter/filter_test.go b/filter/filter_test.go index 6880450c..faaf3a60 100644 --- a/filter/filter_test.go +++ b/filter/filter_test.go @@ -32,20 +32,21 @@ import ( "bitbucket.org/ausocean/utils/logger" ) -type d struct { -} +const downscale = 1 -func (d *d) Write(p []byte) (int, error) { return len(p), nil } -func (d *d) Close() error { return nil } +type dumbWriteCloser struct{} + +func (d *dumbWriteCloser) Write(p []byte) (int, error) { return len(p), nil } +func (d *dumbWriteCloser) Close() error { return nil } func BenchmarkBasic(b *testing.B) { - log := logger.New(logger.Debug, &bytes.Buffer{}, true) - cfg := config.Config{Logger: log} + cfg := config.Config{Logger: logger.New(logger.Debug, &bytes.Buffer{}, true)} err := cfg.Validate() if err != nil { b.Fatalf("Config struct is bad: %v#", err) } - buffer := &d{} + + buffer := &dumbWriteCloser{} f := NewBasic(buffer, cfg) b.Log("Frames: ", len(testPackets)) for n := 0; n < b.N; n++ { @@ -59,13 +60,13 @@ func BenchmarkBasic(b *testing.B) { } func BenchmarkDifference(b *testing.B) { - log := logger.New(logger.Debug, &bytes.Buffer{}, true) - cfg := config.Config{Logger: log} + cfg := config.Config{Logger: logger.New(logger.Debug, &bytes.Buffer{}, true)} err := cfg.Validate() if err != nil { b.Fatalf("Config struct is bad: %v#", err) } - buffer := &d{} + + buffer := &dumbWriteCloser{} f := NewDiff(buffer, cfg) b.Log("Frames: ", len(testPackets)) for n := 0; n < b.N; n++ { @@ -79,14 +80,13 @@ func BenchmarkDifference(b *testing.B) { } func BenchmarkKNN(b *testing.B) { - log := logger.New(logger.Debug, &bytes.Buffer{}, true) - cfg := config.Config{Logger: log} + cfg := config.Config{Logger: logger.New(logger.Debug, &bytes.Buffer{}, true), MotionDownscaling: downscale} err := cfg.Validate() if err != nil { b.Fatalf("Config struct is bad: %v#", err) } - cfg.MotionDownscaling = 1 - buffer := &d{} + + buffer := &dumbWriteCloser{} f := NewKNN(buffer, cfg) b.Log("Frames: ", len(testPackets)) for n := 0; n < b.N; n++ { @@ -100,14 +100,13 @@ func BenchmarkKNN(b *testing.B) { } func BenchmarkMOG(b *testing.B) { - log := logger.New(logger.Debug, &bytes.Buffer{}, true) - cfg := config.Config{Logger: log} + cfg := config.Config{Logger: logger.New(logger.Debug, &bytes.Buffer{}, true), MotionDownscaling: downscale} err := cfg.Validate() if err != nil { b.Fatalf("Config struct is bad: %v#", err) } - cfg.MotionDownscaling = 1 - buffer := &d{} + + buffer := &dumbWriteCloser{} f := NewMOG(buffer, cfg) b.Log("Frames: ", len(testPackets)) for n := 0; n < b.N; n++ {