yay/pacman/pacman_test.go

60 lines
1.4 KiB
Go
Raw Normal View History

package pacman
import "testing"
2017-01-05 17:13:52 +01:00
import "github.com/jguer/yay/util"
import "os"
func benchmarkPrintSearch(search string, b *testing.B) {
old := os.Stdout
_, w, _ := os.Pipe()
os.Stdout = w
for n := 0; n < b.N; n++ {
res, _, _ := Search(append([]string{}, search))
res.PrintSearch()
}
os.Stdout = old
}
func BenchmarkPrintSearchSimpleTopDown(b *testing.B) {
util.SortMode = util.TopDown
benchmarkPrintSearch("chromium", b)
}
func BenchmarkPrintSearchComplexTopDown(b *testing.B) {
util.SortMode = util.TopDown
benchmarkPrintSearch("linux", b)
}
func BenchmarkPrintSearchSimpleBottomUp(b *testing.B) {
util.SortMode = util.BottomUp
benchmarkPrintSearch("chromium", b)
}
func BenchmarkPrintSearchComplexBottomUp(b *testing.B) {
util.SortMode = util.BottomUp
benchmarkPrintSearch("linux", b)
}
func benchmarkSearch(search string, b *testing.B) {
for n := 0; n < b.N; n++ {
Search(append([]string{}, search))
}
}
2017-01-05 17:13:52 +01:00
func BenchmarkSearchSimpleTopDown(b *testing.B) {
util.SortMode = util.TopDown
2017-01-05 17:13:52 +01:00
benchmarkSearch("chromium", b)
}
func BenchmarkSearchSimpleBottomUp(b *testing.B) {
util.SortMode = util.BottomUp
2017-01-05 17:13:52 +01:00
benchmarkSearch("chromium", b)
}
func BenchmarkSearchComplexTopDown(b *testing.B) {
util.SortMode = util.TopDown
benchmarkSearch("linux", b)
}
func BenchmarkSearchComplexBottomUp(b *testing.B) {
util.SortMode = util.BottomUp
benchmarkSearch("linux", b)
}