filter: benchmark: tidying code

This commit is contained in:
Ella Pietraroia 2020-02-11 12:14:21 +10:30
parent e73be1e30a
commit 8dfddfbc1e
1 changed files with 17 additions and 18 deletions

View File

@ -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++ {