mirror of https://bitbucket.org/ausocean/av.git
Merged in benchmark (pull request #374)
Benchmarking for filters Approved-by: Saxon Milton <saxon.milton@gmail.com>
This commit is contained in:
commit
2ee8ded809
|
@ -0,0 +1,120 @@
|
||||||
|
/*
|
||||||
|
DESCRIPTION
|
||||||
|
filter_test.go contains benchmarking tests for each filter implementation.
|
||||||
|
|
||||||
|
AUTHORS
|
||||||
|
Ella Pietraroia <ella@ausocean.org>
|
||||||
|
|
||||||
|
LICENSE
|
||||||
|
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
|
||||||
|
Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
option) any later version.
|
||||||
|
|
||||||
|
It is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
in gpl.txt. If not, see http://www.gnu.org/licenses.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package filter
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"bitbucket.org/ausocean/av/revid/config"
|
||||||
|
"bitbucket.org/ausocean/utils/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
const downscale = 1
|
||||||
|
|
||||||
|
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) {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
f := NewBasic(&dumbWriteCloser{}, cfg)
|
||||||
|
for n := 0; n < b.N; n++ {
|
||||||
|
for _, x := range testPackets {
|
||||||
|
_, err := f.Write(x)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("cannot write to basic filter: %v#", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
b.Log("Frames: ", len(testPackets))
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkDifference(b *testing.B) {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
f := NewDiff(&dumbWriteCloser{}, cfg)
|
||||||
|
for n := 0; n < b.N; n++ {
|
||||||
|
for _, x := range testPackets {
|
||||||
|
_, err := f.Write(x)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("cannot write to diff filter: %v#", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
b.Log("Frames: ", len(testPackets))
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkKNN(b *testing.B) {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
f := NewKNN(&dumbWriteCloser{}, cfg)
|
||||||
|
for n := 0; n < b.N; n++ {
|
||||||
|
for _, x := range testPackets {
|
||||||
|
_, err := f.Write(x)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("cannot write to KNN filter: %v#", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
b.Log("Frames: ", len(testPackets))
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkMOG(b *testing.B) {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
f := NewMOG(&dumbWriteCloser{}, cfg)
|
||||||
|
for n := 0; n < b.N; n++ {
|
||||||
|
for _, x := range testPackets {
|
||||||
|
_, err := f.Write(x)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("cannot write to MOG filter: %v#", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
b.Log("Frames: ", len(testPackets))
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue