2016-12-02 15:58:03 +01:00
|
|
|
package pacman
|
|
|
|
|
|
|
|
import "testing"
|
2017-01-05 17:13:52 +01:00
|
|
|
import "github.com/jguer/yay/util"
|
2017-01-05 17:42:06 +01:00
|
|
|
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++ {
|
2017-02-18 16:29:40 +01:00
|
|
|
res, _, _ := Search(append([]string{}, search))
|
2017-01-05 17:42:06 +01:00
|
|
|
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)
|
|
|
|
}
|
2016-12-02 15:58:03 +01:00
|
|
|
|
|
|
|
func benchmarkSearch(search string, b *testing.B) {
|
|
|
|
for n := 0; n < b.N; n++ {
|
2017-02-18 16:29:40 +01:00
|
|
|
Search(append([]string{}, search))
|
2016-12-02 15:58:03 +01:00
|
|
|
}
|
|
|
|
}
|
2017-01-05 17:13:52 +01:00
|
|
|
func BenchmarkSearchSimpleTopDown(b *testing.B) {
|
2017-01-05 17:42:06 +01:00
|
|
|
util.SortMode = util.TopDown
|
2017-01-05 17:13:52 +01:00
|
|
|
benchmarkSearch("chromium", b)
|
|
|
|
}
|
2017-01-05 17:42:06 +01:00
|
|
|
|
|
|
|
func BenchmarkSearchSimpleBottomUp(b *testing.B) {
|
|
|
|
util.SortMode = util.BottomUp
|
2017-01-05 17:13:52 +01:00
|
|
|
benchmarkSearch("chromium", b)
|
|
|
|
}
|
2017-01-05 17:42:06 +01:00
|
|
|
|
|
|
|
func BenchmarkSearchComplexTopDown(b *testing.B) {
|
|
|
|
util.SortMode = util.TopDown
|
|
|
|
benchmarkSearch("linux", b)
|
|
|
|
}
|
|
|
|
func BenchmarkSearchComplexBottomUp(b *testing.B) {
|
|
|
|
util.SortMode = util.BottomUp
|
|
|
|
benchmarkSearch("linux", b)
|
|
|
|
}
|