filter: benchmark: upadte headers, add consts, print to log

This commit is contained in:
Ella Pietraroia 2020-02-07 10:40:14 +10:30
parent ab30dff020
commit 42fe6e05ac
2 changed files with 41 additions and 23 deletions

View File

@ -1,15 +1,12 @@
/* /*
NAME
filter_test.go
DESCRIPTION DESCRIPTION
See Readme.md filter_test.go contains benchmarking tests for each filter implementation.
AUTHORS AUTHORS
Ella Pietraroia <ella@ausocean.org> Ella Pietraroia <ella@ausocean.org>
LICENSE 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 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 under the terms of the GNU General Public License as published by the
@ -28,17 +25,41 @@ LICENSE
package filter package filter
import ( import (
"fmt"
"io" "io"
"os" "os"
"testing" "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) { func BenchmarkBasic(b *testing.B) {
file, _ := os.Create("testout/test_outBasic.mjpeg") file, _ := os.Create(outBasic)
w := io.WriteCloser(file) f := NewBasic(io.WriteCloser(file), debug, BasicThreshold, BasicPixels)
f := NewBasic(w, false, 45000, 1000) b.Log("\nFrames: ", len(testPackets))
fmt.Print("\nFrames: ", len(testPackets), "\t")
for n := 0; n < b.N; n++ { for n := 0; n < b.N; n++ {
for _, x := range testPackets { for _, x := range testPackets {
f.Write(x) f.Write(x)
@ -47,10 +68,9 @@ func BenchmarkBasic(b *testing.B) {
} }
func BenchmarkDifference(b *testing.B) { func BenchmarkDifference(b *testing.B) {
file, _ := os.Create("testout/test_outDiff.mjpeg") file, _ := os.Create(outDiff)
w := io.WriteCloser(file) f := NewDifference(io.WriteCloser(file), debug, DiffThreshold)
f := NewDifference(w, false, 3) b.Log("\nFrames: ", len(testPackets))
fmt.Print("\nFrames: ", len(testPackets), "\t")
for n := 0; n < b.N; n++ { for n := 0; n < b.N; n++ {
for _, x := range testPackets { for _, x := range testPackets {
f.Write(x) f.Write(x)
@ -59,10 +79,9 @@ func BenchmarkDifference(b *testing.B) {
} }
func BenchmarkKNN(b *testing.B) { func BenchmarkKNN(b *testing.B) {
file, _ := os.Create("testout/test_outKNN.mjpeg") file, _ := os.Create(outKNN)
w := io.WriteCloser(file) f := NewKNN(io.WriteCloser(file), KNNMinArea, KNNThreshold, KNNHistory, KNNKernel, debug, motionInterval, motionDownscaling)
f := NewKNN(w, 25, 20, 300, 9, false, 1, 1) b.Log("\nFrames: ", len(testPackets))
fmt.Print("\nFrames: ", len(testPackets), "\t")
for n := 0; n < b.N; n++ { for n := 0; n < b.N; n++ {
for _, x := range testPackets { for _, x := range testPackets {
f.Write(x) f.Write(x)
@ -71,10 +90,9 @@ func BenchmarkKNN(b *testing.B) {
} }
func BenchmarkMOG(b *testing.B) { func BenchmarkMOG(b *testing.B) {
file, _ := os.Create("testout/test_outMOG.mjpeg") file, _ := os.Create(outMOG)
w := io.WriteCloser(file) f := NewMOG(io.WriteCloser(file), MOGMinArea, MOGThreshold, MOGHistory, debug, motionInterval, motionDownscaling)
f := NewMOG(w, 25, 20, 500, false, 1, 1) b.Log("\nFrames: ", len(testPackets))
fmt.Print("\nFrames: ", len(testPackets), "\t")
for n := 0; n < b.N; n++ { for n := 0; n < b.N; n++ {
for _, x := range testPackets { for _, x := range testPackets {
f.Write(x) f.Write(x)

View File

@ -8,7 +8,7 @@ AUTHOR
Ella Pietraroia <ella@ausocean.org> Ella Pietraroia <ella@ausocean.org>
LICENSE 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 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 under the terms of the GNU General Public License as published by the