print_test.go 765 B

123456789101112131415161718192021222324252627282930313233343536
  1. package main
  2. import (
  3. "os"
  4. "testing"
  5. )
  6. func benchmarkPrintSearch(search string, b *testing.B) {
  7. old := os.Stdout
  8. _, w, _ := os.Pipe()
  9. os.Stdout = w
  10. for n := 0; n < b.N; n++ {
  11. res, _, _ := queryRepo(append([]string{}, search))
  12. res.printSearch()
  13. }
  14. os.Stdout = old
  15. }
  16. func BenchmarkPrintSearchSimpleTopDown(b *testing.B) {
  17. config.SortMode = TopDown
  18. benchmarkPrintSearch("chromium", b)
  19. }
  20. func BenchmarkPrintSearchComplexTopDown(b *testing.B) {
  21. config.SortMode = TopDown
  22. benchmarkPrintSearch("linux", b)
  23. }
  24. func BenchmarkPrintSearchSimpleBottomUp(b *testing.B) {
  25. config.SortMode = BottomUp
  26. benchmarkPrintSearch("chromium", b)
  27. }
  28. func BenchmarkPrintSearchComplexBottomUp(b *testing.B) {
  29. config.SortMode = BottomUp
  30. benchmarkPrintSearch("linux", b)
  31. }