Changed benchmark output. Fixed all downtop (facepalm)

This commit is contained in:
Jguer 2017-01-05 16:42:06 +00:00
parent 7e2625d362
commit dcff8af505
3 changed files with 64 additions and 16 deletions

View file

@ -1,11 +1,13 @@
package aur
import (
"os"
"reflect"
"testing"
)
func TestSearch(t *testing.T) {
eN := "yay"
eD := "Yet another yogurt. Pacman wrapper with AUR support written in go."
result, _, err := Search("yay", true)
@ -27,6 +29,7 @@ func TestSearch(t *testing.T) {
}
func benchmarkSearch(search string, sort bool, b *testing.B) {
for n := 0; n < b.N; n++ {
Search(search, sort)
}
@ -38,6 +41,7 @@ func BenchmarkSearchSimpleSorted(b *testing.B) { benchmarkSearch("yay", true, b
func BenchmarkSearchComplexSorted(b *testing.B) { benchmarkSearch("linux", true, b) }
func TestInfo(t *testing.T) {
eN := "yay"
eD := "Yet another yogurt. Pacman wrapper with AUR support written in go."
eM := []string{"go", "git"}
@ -60,14 +64,26 @@ func TestInfo(t *testing.T) {
}
func TestUpgrade(t *testing.T) {
old := os.Stdout
_, w, _ := os.Pipe()
os.Stdout = w
err := Upgrade([]string{})
if err != nil {
t.Fatalf("Expected err to be nil but it was %s", err)
}
os.Stdout = old
}
func BenchmarkUpgrade(b *testing.B) {
old := os.Stdout
_, w, _ := os.Pipe()
os.Stdout = w
for n := 0; n < b.N; n++ {
Upgrade([]string{})
}
os.Stdout = old
}

View file

@ -26,12 +26,6 @@ type Result struct {
// PacmanConf describes the default pacman config file
const PacmanConf string = "/etc/pacman.conf"
// Determines NumberMenu and Search Order
const (
DownTop = iota
TopDown
)
var conf alpm.PacmanConfig
func init() {
@ -85,7 +79,7 @@ func Search(pkgName string) (s RepoSearch, n int, err error) {
var installed bool
dbS := dbList.Slice()
var f int
if util.SortMode == DownTop {
if util.SortMode == util.BottomUp {
f = len(dbS) - 1
} else {
f = 0
@ -95,7 +89,7 @@ func Search(pkgName string) (s RepoSearch, n int, err error) {
pkgS := dbS[f].PkgCache().Slice()
var i int
if util.SortMode == DownTop {
if util.SortMode == util.BottomUp {
i = len(pkgS) - 1
} else {
i = 0
@ -120,7 +114,7 @@ func Search(pkgName string) (s RepoSearch, n int, err error) {
n++
}
if util.SortMode == DownTop {
if util.SortMode == util.BottomUp {
if i > 0 {
i--
} else {
@ -135,7 +129,7 @@ func Search(pkgName string) (s RepoSearch, n int, err error) {
}
}
if util.SortMode == DownTop {
if util.SortMode == util.BottomUp {
if f > 0 {
f--
} else {

View file

@ -2,20 +2,58 @@ package pacman
import "testing"
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(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(search)
}
}
func BenchmarkSearchSimpleTopDown(b *testing.B) {
util.SortMode = TopDown
util.SortMode = util.TopDown
benchmarkSearch("chromium", b)
}
func BenchmarkSearchComplexTopDown(b *testing.B) { util.SortMode = TopDown; benchmarkSearch("linux", b) }
func BenchmarkSearchSimpleDownTop(b *testing.B) {
util.SortMode = DownTop
func BenchmarkSearchSimpleBottomUp(b *testing.B) {
util.SortMode = util.BottomUp
benchmarkSearch("chromium", b)
}
func BenchmarkSearchComplexDownTop(b *testing.B) { util.SortMode = DownTop; benchmarkSearch("linux", 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)
}