add scanner benchmarking

This commit is contained in:
sentriz
2019-07-04 14:08:44 +01:00
parent 5fa6fb6394
commit f4b766e86d

66
scanner/scanner_test.go Normal file
View File

@@ -0,0 +1,66 @@
package scanner
import (
"io/ioutil"
"log"
"testing"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"github.com/sentriz/gonic/db"
)
var testScanner *Scanner
func init() {
db, err := db.New(":memory:")
if err != nil {
log.Fatalf("error opening database: %v\n", err)
}
// benchmarks aren't real code are they? >:)
// here is an absolute path to my music directory
testScanner = New(db, "/home/senan/music")
log.SetOutput(ioutil.Discard)
}
func resetTables(db *gorm.DB) {
tx := db.Begin()
defer tx.Commit()
tx.Exec("delete from tracks")
tx.Exec("delete from artists")
tx.Exec("delete from albums")
}
func resetTablesPause(db *gorm.DB, b *testing.B) {
b.StopTimer()
defer b.StartTimer()
resetTables(db)
}
func BenchmarkScanFresh(b *testing.B) {
for n := 0; n < b.N; n++ {
resetTablesPause(testScanner.db, b)
testScanner.Start()
}
}
func BenchmarkScanIncremental(b *testing.B) {
// do a full scan and reset
testScanner.Start()
b.ResetTimer()
// do the inc scans
for n := 0; n < b.N; n++ {
testScanner.Start()
}
}
// RESULTS fresh
// 20 times / 1.436
// 20 times / 1.39
// RESULTS inc
// 100 times / 1.86
// 100 times / 1.9
// 100 times / 1.5
// 100 times / 1.48