filter: benchmark: change from wiriting output to file, to wiritng to dummy struct

This commit is contained in:
Ella Pietraroia 2020-02-07 15:55:02 +10:30
parent d7fa988272
commit 87498f125d
1 changed files with 14 additions and 17 deletions

View File

@ -25,18 +25,9 @@ LICENSE
package filter
import (
"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
@ -57,9 +48,15 @@ const (
MOGHistory = 500
)
type d struct {
}
func (d *d) Write(p []byte) (int, error) { return len(p), nil }
func (d *d) Close() error { return nil }
func BenchmarkBasic(b *testing.B) {
file, _ := os.Create(outBasic)
f := NewBasic(io.WriteCloser(file), debug, BasicThreshold, BasicPixels)
buffer := &d{}
f := NewBasic(buffer, debug, BasicThreshold, BasicPixels)
b.Log("Frames: ", len(testPackets))
for n := 0; n < b.N; n++ {
for _, x := range testPackets {
@ -72,8 +69,8 @@ func BenchmarkBasic(b *testing.B) {
}
func BenchmarkDifference(b *testing.B) {
file, _ := os.Create(outDiff)
f := NewDifference(io.WriteCloser(file), debug, DiffThreshold)
buffer := &d{}
f := NewDifference(buffer, debug, DiffThreshold)
b.Log("Frames: ", len(testPackets))
for n := 0; n < b.N; n++ {
for _, x := range testPackets {
@ -86,8 +83,8 @@ func BenchmarkDifference(b *testing.B) {
}
func BenchmarkKNN(b *testing.B) {
file, _ := os.Create(outKNN)
f := NewKNN(io.WriteCloser(file), KNNMinArea, KNNThreshold, KNNHistory, KNNKernel, debug, motionInterval, motionDownscaling)
buffer := &d{}
f := NewKNN(buffer, KNNMinArea, KNNThreshold, KNNHistory, KNNKernel, debug, motionInterval, motionDownscaling)
b.Log("Frames: ", len(testPackets))
for n := 0; n < b.N; n++ {
for _, x := range testPackets {
@ -100,8 +97,8 @@ func BenchmarkKNN(b *testing.B) {
}
func BenchmarkMOG(b *testing.B) {
file, _ := os.Create(outMOG)
f := NewMOG(io.WriteCloser(file), MOGMinArea, MOGThreshold, MOGHistory, debug, motionInterval, motionDownscaling)
buffer := &d{}
f := NewMOG(buffer, MOGMinArea, MOGThreshold, MOGHistory, debug, motionInterval, motionDownscaling)
b.Log("Frames: ", len(testPackets))
for n := 0; n < b.N; n++ {
for _, x := range testPackets {