mirror of
https://github.com/Jguer/yay
synced 2024-10-31 04:12:51 +00:00
Changed benchmark output. Fixed all downtop (facepalm)
This commit is contained in:
parent
7e2625d362
commit
dcff8af505
3 changed files with 64 additions and 16 deletions
|
@ -1,11 +1,13 @@
|
||||||
package aur
|
package aur
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSearch(t *testing.T) {
|
func TestSearch(t *testing.T) {
|
||||||
|
|
||||||
eN := "yay"
|
eN := "yay"
|
||||||
eD := "Yet another yogurt. Pacman wrapper with AUR support written in go."
|
eD := "Yet another yogurt. Pacman wrapper with AUR support written in go."
|
||||||
result, _, err := Search("yay", true)
|
result, _, err := Search("yay", true)
|
||||||
|
@ -27,6 +29,7 @@ func TestSearch(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchmarkSearch(search string, sort bool, b *testing.B) {
|
func benchmarkSearch(search string, sort bool, b *testing.B) {
|
||||||
|
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
Search(search, sort)
|
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 BenchmarkSearchComplexSorted(b *testing.B) { benchmarkSearch("linux", true, b) }
|
||||||
|
|
||||||
func TestInfo(t *testing.T) {
|
func TestInfo(t *testing.T) {
|
||||||
|
|
||||||
eN := "yay"
|
eN := "yay"
|
||||||
eD := "Yet another yogurt. Pacman wrapper with AUR support written in go."
|
eD := "Yet another yogurt. Pacman wrapper with AUR support written in go."
|
||||||
eM := []string{"go", "git"}
|
eM := []string{"go", "git"}
|
||||||
|
@ -60,14 +64,26 @@ func TestInfo(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpgrade(t *testing.T) {
|
func TestUpgrade(t *testing.T) {
|
||||||
|
old := os.Stdout
|
||||||
|
_, w, _ := os.Pipe()
|
||||||
|
os.Stdout = w
|
||||||
|
|
||||||
err := Upgrade([]string{})
|
err := Upgrade([]string{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Expected err to be nil but it was %s", err)
|
t.Fatalf("Expected err to be nil but it was %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
os.Stdout = old
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkUpgrade(b *testing.B) {
|
func BenchmarkUpgrade(b *testing.B) {
|
||||||
|
old := os.Stdout
|
||||||
|
_, w, _ := os.Pipe()
|
||||||
|
os.Stdout = w
|
||||||
|
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
Upgrade([]string{})
|
Upgrade([]string{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
os.Stdout = old
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,12 +26,6 @@ type Result struct {
|
||||||
// PacmanConf describes the default pacman config file
|
// PacmanConf describes the default pacman config file
|
||||||
const PacmanConf string = "/etc/pacman.conf"
|
const PacmanConf string = "/etc/pacman.conf"
|
||||||
|
|
||||||
// Determines NumberMenu and Search Order
|
|
||||||
const (
|
|
||||||
DownTop = iota
|
|
||||||
TopDown
|
|
||||||
)
|
|
||||||
|
|
||||||
var conf alpm.PacmanConfig
|
var conf alpm.PacmanConfig
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -85,7 +79,7 @@ func Search(pkgName string) (s RepoSearch, n int, err error) {
|
||||||
var installed bool
|
var installed bool
|
||||||
dbS := dbList.Slice()
|
dbS := dbList.Slice()
|
||||||
var f int
|
var f int
|
||||||
if util.SortMode == DownTop {
|
if util.SortMode == util.BottomUp {
|
||||||
f = len(dbS) - 1
|
f = len(dbS) - 1
|
||||||
} else {
|
} else {
|
||||||
f = 0
|
f = 0
|
||||||
|
@ -95,7 +89,7 @@ func Search(pkgName string) (s RepoSearch, n int, err error) {
|
||||||
pkgS := dbS[f].PkgCache().Slice()
|
pkgS := dbS[f].PkgCache().Slice()
|
||||||
|
|
||||||
var i int
|
var i int
|
||||||
if util.SortMode == DownTop {
|
if util.SortMode == util.BottomUp {
|
||||||
i = len(pkgS) - 1
|
i = len(pkgS) - 1
|
||||||
} else {
|
} else {
|
||||||
i = 0
|
i = 0
|
||||||
|
@ -120,7 +114,7 @@ func Search(pkgName string) (s RepoSearch, n int, err error) {
|
||||||
n++
|
n++
|
||||||
}
|
}
|
||||||
|
|
||||||
if util.SortMode == DownTop {
|
if util.SortMode == util.BottomUp {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
i--
|
i--
|
||||||
} else {
|
} 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 {
|
if f > 0 {
|
||||||
f--
|
f--
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2,20 +2,58 @@ package pacman
|
||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
import "github.com/jguer/yay/util"
|
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) {
|
func benchmarkSearch(search string, b *testing.B) {
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
Search(search)
|
Search(search)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkSearchSimpleTopDown(b *testing.B) {
|
func BenchmarkSearchSimpleTopDown(b *testing.B) {
|
||||||
util.SortMode = TopDown
|
util.SortMode = util.TopDown
|
||||||
benchmarkSearch("chromium", b)
|
benchmarkSearch("chromium", b)
|
||||||
}
|
}
|
||||||
func BenchmarkSearchComplexTopDown(b *testing.B) { util.SortMode = TopDown; benchmarkSearch("linux", b) }
|
|
||||||
func BenchmarkSearchSimpleDownTop(b *testing.B) {
|
func BenchmarkSearchSimpleBottomUp(b *testing.B) {
|
||||||
util.SortMode = DownTop
|
util.SortMode = util.BottomUp
|
||||||
benchmarkSearch("chromium", b)
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue