yay/pacman/pacman_test.go

63 lines
1.5 KiB
Go
Raw Normal View History

package pacman
2017-05-07 03:43:49 +02:00
import (
"os"
"testing"
"github.com/jguer/yay/config"
)
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) {
2017-05-07 03:43:49 +02:00
config.YayConf.SortMode = config.TopDown
benchmarkPrintSearch("chromium", b)
}
func BenchmarkPrintSearchComplexTopDown(b *testing.B) {
2017-05-07 03:43:49 +02:00
config.YayConf.SortMode = config.TopDown
benchmarkPrintSearch("linux", b)
}
func BenchmarkPrintSearchSimpleBottomUp(b *testing.B) {
2017-05-07 03:43:49 +02:00
config.YayConf.SortMode = config.BottomUp
benchmarkPrintSearch("chromium", b)
}
func BenchmarkPrintSearchComplexBottomUp(b *testing.B) {
2017-05-07 03:43:49 +02:00
config.YayConf.SortMode = config.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) {
2017-05-07 03:43:49 +02:00
config.YayConf.SortMode = config.TopDown
2017-01-05 17:13:52 +01:00
benchmarkSearch("chromium", b)
}
func BenchmarkSearchSimpleBottomUp(b *testing.B) {
2017-05-07 03:43:49 +02:00
config.YayConf.SortMode = config.BottomUp
2017-01-05 17:13:52 +01:00
benchmarkSearch("chromium", b)
}
func BenchmarkSearchComplexTopDown(b *testing.B) {
2017-05-07 03:43:49 +02:00
config.YayConf.SortMode = config.TopDown
benchmarkSearch("linux", b)
}
func BenchmarkSearchComplexBottomUp(b *testing.B) {
2017-05-07 03:43:49 +02:00
config.YayConf.SortMode = config.BottomUp
benchmarkSearch("linux", b)
}