benchfilter.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright (C) 2015 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. // +build ignore
  7. // Neatly format benchmarking output which otherwise looks like crap.
  8. package main
  9. import (
  10. "bufio"
  11. "fmt"
  12. "os"
  13. "regexp"
  14. "strings"
  15. "text/tabwriter"
  16. )
  17. var (
  18. benchRe = regexp.MustCompile(`^(Bench[^\s]+)\s+(\d+)\s+(\d+ ns/op)\s*(\d+ B/op)?\s*(\d+ allocs/op)?`)
  19. )
  20. func main() {
  21. tw := tabwriter.NewWriter(os.Stdout, 1, 1, 1, ' ', 0)
  22. br := bufio.NewScanner(os.Stdin)
  23. n := 0
  24. for br.Scan() {
  25. line := br.Text()
  26. if match := benchRe.FindStringSubmatch(line); match != nil {
  27. n++
  28. for i := range match[2:] {
  29. match[2+i] = fmt.Sprintf("%16s", match[2+i])
  30. }
  31. tw.Write([]byte(strings.Join(match[1:], "\t") + "\n"))
  32. } else if n > 0 && strings.HasPrefix(line, "ok") {
  33. n = 0
  34. tw.Flush()
  35. fmt.Printf("%s\n\n", line)
  36. }
  37. }
  38. tw.Flush()
  39. }