From 42fe6e05ac1c7f3525136acb3a99335702d9bb1d Mon Sep 17 00:00:00 2001 From: Ella Pietraroia Date: Fri, 7 Feb 2020 10:40:14 +1030 Subject: [PATCH] filter: benchmark: upadte headers, add consts, print to log --- filter/filter_test.go | 62 ++++++++++++++++++++++++++++--------------- filter/tests.go | 2 +- 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/filter/filter_test.go b/filter/filter_test.go index 4e4e3fce..a6951cf6 100644 --- a/filter/filter_test.go +++ b/filter/filter_test.go @@ -1,15 +1,12 @@ /* -NAME - filter_test.go - DESCRIPTION - See Readme.md + filter_test.go contains benchmarking tests for each filter implementation. AUTHORS Ella Pietraroia LICENSE - This is Copyright (C) 2019 the Australian Ocean Lab (AusOcean). + This is Copyright (C) 2020 the Australian Ocean Lab (AusOcean). It is free software: you can redistribute it and/or modify them under the terms of the GNU General Public License as published by the @@ -28,17 +25,41 @@ LICENSE package filter import ( - "fmt" "io" "os" "testing" ) +const ( + outBasic = "testout/test_outBasic.mjpeg" + outDiff = "testout/test_outDiff.mjpeg" + outKNN = "testout/test_outKNN.mjpeg" + outMOG = "testout/test_outMOG.mjpeg" +) +const ( + debug = false + motionDownscaling = 1 + motionInterval = 1 + + BasicThreshold = 45000 + BasicPixels = 1000 + + DiffThreshold = 3 + + KNNMinArea = 25.0 + KNNThreshold = 300 + KNNHistory = 300 + KNNKernel = 9 + + MOGMinArea = 25.0 + MOGThreshold = 20.0 + MOGHistory = 500 +) + func BenchmarkBasic(b *testing.B) { - file, _ := os.Create("testout/test_outBasic.mjpeg") - w := io.WriteCloser(file) - f := NewBasic(w, false, 45000, 1000) - fmt.Print("\nFrames: ", len(testPackets), "\t") + file, _ := os.Create(outBasic) + f := NewBasic(io.WriteCloser(file), debug, BasicThreshold, BasicPixels) + b.Log("\nFrames: ", len(testPackets)) for n := 0; n < b.N; n++ { for _, x := range testPackets { f.Write(x) @@ -47,10 +68,9 @@ func BenchmarkBasic(b *testing.B) { } func BenchmarkDifference(b *testing.B) { - file, _ := os.Create("testout/test_outDiff.mjpeg") - w := io.WriteCloser(file) - f := NewDifference(w, false, 3) - fmt.Print("\nFrames: ", len(testPackets), "\t") + file, _ := os.Create(outDiff) + f := NewDifference(io.WriteCloser(file), debug, DiffThreshold) + b.Log("\nFrames: ", len(testPackets)) for n := 0; n < b.N; n++ { for _, x := range testPackets { f.Write(x) @@ -59,10 +79,9 @@ func BenchmarkDifference(b *testing.B) { } func BenchmarkKNN(b *testing.B) { - file, _ := os.Create("testout/test_outKNN.mjpeg") - w := io.WriteCloser(file) - f := NewKNN(w, 25, 20, 300, 9, false, 1, 1) - fmt.Print("\nFrames: ", len(testPackets), "\t") + file, _ := os.Create(outKNN) + f := NewKNN(io.WriteCloser(file), KNNMinArea, KNNThreshold, KNNHistory, KNNKernel, debug, motionInterval, motionDownscaling) + b.Log("\nFrames: ", len(testPackets)) for n := 0; n < b.N; n++ { for _, x := range testPackets { f.Write(x) @@ -71,10 +90,9 @@ func BenchmarkKNN(b *testing.B) { } func BenchmarkMOG(b *testing.B) { - file, _ := os.Create("testout/test_outMOG.mjpeg") - w := io.WriteCloser(file) - f := NewMOG(w, 25, 20, 500, false, 1, 1) - fmt.Print("\nFrames: ", len(testPackets), "\t") + file, _ := os.Create(outMOG) + f := NewMOG(io.WriteCloser(file), MOGMinArea, MOGThreshold, MOGHistory, debug, motionInterval, motionDownscaling) + b.Log("\nFrames: ", len(testPackets)) for n := 0; n < b.N; n++ { for _, x := range testPackets { f.Write(x) diff --git a/filter/tests.go b/filter/tests.go index 8418a80f..510a5ef1 100644 --- a/filter/tests.go +++ b/filter/tests.go @@ -8,7 +8,7 @@ AUTHOR Ella Pietraroia LICENSE - Copyright (C) 2019 the Australian Ocean Lab (AusOcean) + Copyright (C) 2020 the Australian Ocean Lab (AusOcean) It is free software: you can redistribute it and/or modify them under the terms of the GNU General Public License as published by the