Added Pacman benchmarks, topdown and downtop return same list, just inverted

This commit is contained in:
Jguer 2016-12-02 14:58:03 +00:00
parent 0d44ecc0ea
commit 16a33d706b
3 changed files with 83 additions and 10 deletions

View file

@ -31,6 +31,7 @@ const (
// Config copies settings over to AUR and Pacman packages
func Config() {
aur.SortMode = SortMode
pac.SortMode = SortMode
}
// NumberMenu presents a CLI for selecting packages to install.
@ -40,6 +41,9 @@ func NumberMenu(pkgName string, flags []string) (err error) {
var args []string
a, nA, err := aur.Search(pkgName, true)
if err != nil {
fmt.Println("Error during AUR search:", err)
}
r, nR, err := pac.Search(pkgName)
if err != nil {
return
@ -158,7 +162,7 @@ func Search(pkg string) (err error) {
return err
}
if aur.SortMode == aur.DownTop {
if SortMode == aur.DownTop {
a.PrintSearch(SearchMode)
r.PrintSearch(SearchMode)
} else {

View file

@ -25,6 +25,15 @@ type Result struct {
// PacmanConf describes the default pacman config file
const PacmanConf string = "/etc/pacman.conf"
// SortMode NumberMenu and Search
var SortMode = DownTop
// Determines NumberMenu and Search Order
const (
DownTop = iota
TopDown
)
var conf alpm.PacmanConfig
func init() {
@ -76,26 +85,72 @@ func Search(pkgName string) (s RepoSearch, n int, err error) {
}
var installed bool
for _, db := range dbList.Slice() {
for _, pkg := range db.PkgCache().Slice() {
if strings.Contains(pkg.Name(), pkgName) {
if r, _ := localDb.PkgByName(pkg.Name()); r != nil {
dbS := dbList.Slice()
var f int
if SortMode == DownTop {
f = len(dbS) - 1
} else {
f = 0
}
for {
pkgS := dbS[f].PkgCache().Slice()
var i int
if SortMode == DownTop {
i = len(pkgS) - 1
} else {
i = 0
}
for {
if strings.Contains(pkgS[i].Name(), pkgName) {
if r, _ := localDb.PkgByName(pkgS[i].Name()); r != nil {
installed = true
} else {
installed = false
}
s = append(s, Result{
Name: pkg.Name(),
Description: pkg.Description(),
Version: pkg.Version(),
Repository: db.Name(),
Group: strings.Join(pkg.Groups().Slice(), ","),
Name: pkgS[i].Name(),
Description: pkgS[i].Description(),
Version: pkgS[i].Version(),
Repository: dbS[f].Name(),
Group: strings.Join(pkgS[i].Groups().Slice(), ","),
Installed: installed,
})
n++
}
if SortMode == DownTop {
if i > 0 {
i--
} else {
break
}
} else {
if i < len(pkgS)-1 {
i++
} else {
break
}
}
}
if SortMode == DownTop {
if f > 0 {
f--
} else {
break
}
} else {
if f < len(dbS)-1 {
f++
} else {
break
}
}
}
return
}

14
pacman/pacman_test.go Normal file
View file

@ -0,0 +1,14 @@
package pacman
import "testing"
func benchmarkSearch(search string, b *testing.B) {
for n := 0; n < b.N; n++ {
Search(search)
}
}
func BenchmarkSearchSimpleTopDown(b *testing.B) { SortMode = TopDown; benchmarkSearch("chromium", b) }
func BenchmarkSearchComplexTopDown(b *testing.B) { SortMode = TopDown; benchmarkSearch("linux", b) }
func BenchmarkSearchSimpleDownTop(b *testing.B) { SortMode = DownTop; benchmarkSearch("chromium", b) }
func BenchmarkSearchComplexDownTop(b *testing.B) { SortMode = DownTop; benchmarkSearch("linux", b) }