Skip to content

Commit

Permalink
Changed benchmark output. Fixed all downtop (facepalm)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jguer committed Jan 5, 2017
1 parent 7e2625d commit dcff8af
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 16 deletions.
16 changes: 16 additions & 0 deletions aur/aur_test.go
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
}
Expand All @@ -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"}
Expand All @@ -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
}
14 changes: 4 additions & 10 deletions pacman/pacman.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
50 changes: 44 additions & 6 deletions pacman/pacman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit dcff8af

Please sign in to comment.