Filter: Benchmark: Merging in new way of calling new filters

This commit is contained in:
Ella Pietraroia 2020-02-11 10:55:28 +10:30
parent a658e39c7c
commit ee3781eddc
1 changed files with 34 additions and 175 deletions

View File

@ -22,89 +22,16 @@ LICENSE
in gpl.txt. If not, see http://www.gnu.org/licenses.
*/
<<<<<<< HEAD
<<<<<<< HEAD
=======
// To make a new file for testing please go to test repository test/test-data/av/input/motion-detection/byte_saver.go.
>>>>>>> 749cfa17... filter: benchmarks: tidying up code
=======
>>>>>>> 03d46b19... filter: benchmark: chaning descriptions
package filter
import (
<<<<<<< HEAD
"bytes"
"testing"
"bitbucket.org/ausocean/av/revid/config"
"bitbucket.org/ausocean/utils/logger"
)
<<<<<<< HEAD
type d struct {
}
func (d *d) Write(p []byte) (int, error) { return len(p), nil }
func (d *d) Close() error { return nil }
=======
>>>>>>> 749cfa17... filter: benchmarks: tidying up code
func BenchmarkBasic(b *testing.B) {
<<<<<<< HEAD
const BasicThreshold = 45000
const BasicPixels = 1000
buffer := &d{}
f := NewBasic(buffer, BasicThreshold, BasicPixels)
b.Log("Frames: ", len(testPackets))
=======
file, _ := os.Create("testout/test_outBasic.mjpeg")
w := io.WriteCloser(file)
f := NewBasic(w, false, 45000, 1000)
<<<<<<< HEAD
fmt.Print("\nFrames: ", len(testPackets))
>>>>>>> 31ccc30a... benchmark testing file
=======
fmt.Print("\nFrames: ", len(testPackets), "\t")
>>>>>>> 749cfa17... filter: benchmarks: tidying up code
=======
"io"
"os"
"testing"
)
<<<<<<< HEAD
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(outBasic)
f := NewBasic(io.WriteCloser(file), debug, BasicThreshold, BasicPixels)
<<<<<<< HEAD
b.Log("\nFrames: ", len(testPackets))
>>>>>>> 60437c8c... filter: benchmark: upadte headers, add consts, print to log
=======
=======
type d struct {
}
@ -112,13 +39,15 @@ func (d *d) Write(p []byte) (int, error) { return len(p), nil }
func (d *d) Close() error { return nil }
func BenchmarkBasic(b *testing.B) {
const BasicThreshold = 45000
const BasicPixels = 1000
log := logger.New(logger.Debug, &bytes.Buffer{}, true)
cfg := config.Config{Logger: log}
err := cfg.Validate()
if err != nil {
b.Fatalf("Config struct is bad: %v#", err)
}
buffer := &d{}
f := NewBasic(buffer, BasicThreshold, BasicPixels)
>>>>>>> 50e83432... filter: benchmark: move consts to into benchamrks
f := NewBasic(buffer, cfg)
b.Log("Frames: ", len(testPackets))
>>>>>>> 450df394... filter: benchmark: remove \n from log
for n := 0; n < b.N; n++ {
for _, x := range testPackets {
_, err := f.Write(x)
@ -130,14 +59,14 @@ func BenchmarkBasic(b *testing.B) {
}
func BenchmarkDifference(b *testing.B) {
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 50e83432... filter: benchmark: move consts to into benchamrks
const DiffThreshold = 3.0
log := logger.New(logger.Debug, &bytes.Buffer{}, true)
cfg := config.Config{Logger: log}
err := cfg.Validate()
if err != nil {
b.Fatalf("Config struct is bad: %v#", err)
}
buffer := &d{}
f := NewDifference(buffer, DiffThreshold)
f := NewDiff(buffer, cfg)
b.Log("Frames: ", len(testPackets))
for n := 0; n < b.N; n++ {
for _, x := range testPackets {
@ -145,69 +74,21 @@ func BenchmarkDifference(b *testing.B) {
if err != nil {
b.Fatalf("cannot write to diff filter: %v#", err)
}
=======
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)
<<<<<<< HEAD
b.Log("\nFrames: ", len(testPackets))
>>>>>>> 60437c8c... filter: benchmark: upadte headers, add consts, print to log
=======
b.Log("Frames: ", len(testPackets))
>>>>>>> 450df394... filter: benchmark: remove \n from log
for n := 0; n < b.N; n++ {
for _, x := range testPackets {
<<<<<<< HEAD
f.Write(x)
>>>>>>> 31ccc30a... benchmark testing file
=======
_, err := f.Write(x)
if err != nil {
b.Fatalf("cannot write to diff filter: %v#", err)
}
>>>>>>> 3800faf9... filter: benchmark: error checking for write function update descriptions
}
}
}
func BenchmarkKNN(b *testing.B) {
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 50e83432... filter: benchmark: move consts to into benchamrks
const motionDownscaling = 1
const motionInterval = 1
const KNNMinArea = 25.0
const KNNThreshold = 300.0
const KNNHistory = 300
const KNNKernel = 9
log := logger.New(logger.Debug, &bytes.Buffer{}, true)
cfg := config.Config{Logger: log}
err := cfg.Validate()
if err != nil {
b.Fatalf("Config struct is bad: %v#", err)
}
cfg.MotionDownscaling = 1
buffer := &d{}
f := NewKNN(buffer, KNNMinArea, KNNThreshold, KNNHistory, KNNKernel, motionInterval, motionDownscaling)
f := NewKNN(buffer, cfg)
b.Log("Frames: ", len(testPackets))
=======
file, _ := os.Create("testout/test_outKNN.mjpeg")
w := io.WriteCloser(file)
f := NewKNN(w, 25, 20, 300, 9, false, 1, 1)
<<<<<<< HEAD
fmt.Print("\nFrames: ", len(testPackets))
>>>>>>> 31ccc30a... benchmark testing file
=======
fmt.Print("\nFrames: ", len(testPackets), "\t")
>>>>>>> 749cfa17... filter: benchmarks: tidying up code
=======
file, _ := os.Create(outKNN)
f := NewKNN(io.WriteCloser(file), KNNMinArea, KNNThreshold, KNNHistory, KNNKernel, debug, motionInterval, motionDownscaling)
<<<<<<< HEAD
b.Log("\nFrames: ", len(testPackets))
>>>>>>> 60437c8c... filter: benchmark: upadte headers, add consts, print to log
=======
b.Log("Frames: ", len(testPackets))
>>>>>>> 450df394... filter: benchmark: remove \n from log
for n := 0; n < b.N; n++ {
for _, x := range testPackets {
_, err := f.Write(x)
@ -219,38 +100,16 @@ func BenchmarkKNN(b *testing.B) {
}
func BenchmarkMOG(b *testing.B) {
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 50e83432... filter: benchmark: move consts to into benchamrks
const motionDownscaling = 1
const motionInterval = 1
const MOGMinArea = 25.0
const MOGThreshold = 20.0
const MOGHistory = 500
log := logger.New(logger.Debug, &bytes.Buffer{}, true)
cfg := config.Config{Logger: log}
err := cfg.Validate()
if err != nil {
b.Fatalf("Config struct is bad: %v#", err)
}
cfg.MotionDownscaling = 1
buffer := &d{}
f := NewMOG(buffer, MOGMinArea, MOGThreshold, MOGHistory, motionInterval, motionDownscaling)
f := NewMOG(buffer, cfg)
b.Log("Frames: ", len(testPackets))
=======
file, _ := os.Create("testout/test_outMOG.mjpeg")
w := io.WriteCloser(file)
f := NewMOG(w, 25, 20, 500, false, 1, 1)
<<<<<<< HEAD
fmt.Print("\nFrames: ", len(testPackets))
>>>>>>> 31ccc30a... benchmark testing file
=======
fmt.Print("\nFrames: ", len(testPackets), "\t")
>>>>>>> 749cfa17... filter: benchmarks: tidying up code
=======
file, _ := os.Create(outMOG)
f := NewMOG(io.WriteCloser(file), MOGMinArea, MOGThreshold, MOGHistory, debug, motionInterval, motionDownscaling)
<<<<<<< HEAD
b.Log("\nFrames: ", len(testPackets))
>>>>>>> 60437c8c... filter: benchmark: upadte headers, add consts, print to log
=======
b.Log("Frames: ", len(testPackets))
>>>>>>> 450df394... filter: benchmark: remove \n from log
for n := 0; n < b.N; n++ {
for _, x := range testPackets {
_, err := f.Write(x)