pacman_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package pacman
  2. import (
  3. "os"
  4. "testing"
  5. "github.com/jguer/yay/config"
  6. )
  7. func benchmarkPrintSearch(search string, b *testing.B) {
  8. old := os.Stdout
  9. _, w, _ := os.Pipe()
  10. os.Stdout = w
  11. for n := 0; n < b.N; n++ {
  12. res, _, _ := Search(append([]string{}, search))
  13. res.PrintSearch()
  14. }
  15. os.Stdout = old
  16. }
  17. func BenchmarkPrintSearchSimpleTopDown(b *testing.B) {
  18. config.YayConf.SortMode = config.TopDown
  19. benchmarkPrintSearch("chromium", b)
  20. }
  21. func BenchmarkPrintSearchComplexTopDown(b *testing.B) {
  22. config.YayConf.SortMode = config.TopDown
  23. benchmarkPrintSearch("linux", b)
  24. }
  25. func BenchmarkPrintSearchSimpleBottomUp(b *testing.B) {
  26. config.YayConf.SortMode = config.BottomUp
  27. benchmarkPrintSearch("chromium", b)
  28. }
  29. func BenchmarkPrintSearchComplexBottomUp(b *testing.B) {
  30. config.YayConf.SortMode = config.BottomUp
  31. benchmarkPrintSearch("linux", b)
  32. }
  33. func benchmarkSearch(search string, b *testing.B) {
  34. for n := 0; n < b.N; n++ {
  35. Search(append([]string{}, search))
  36. }
  37. }
  38. func BenchmarkSearchSimpleTopDown(b *testing.B) {
  39. config.YayConf.SortMode = config.TopDown
  40. benchmarkSearch("chromium", b)
  41. }
  42. func BenchmarkSearchSimpleBottomUp(b *testing.B) {
  43. config.YayConf.SortMode = config.BottomUp
  44. benchmarkSearch("chromium", b)
  45. }
  46. func BenchmarkSearchComplexTopDown(b *testing.B) {
  47. config.YayConf.SortMode = config.TopDown
  48. benchmarkSearch("linux", b)
  49. }
  50. func BenchmarkSearchComplexBottomUp(b *testing.B) {
  51. config.YayConf.SortMode = config.BottomUp
  52. benchmarkSearch("linux", b)
  53. }