benchfilter.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 http://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. "bytes"
  12. "fmt"
  13. "os"
  14. "regexp"
  15. "text/tabwriter"
  16. )
  17. var (
  18. benchRe = regexp.MustCompile(`^Bench`)
  19. spacesRe = regexp.MustCompile(`\s+`)
  20. numbersRe = regexp.MustCompile(`\b[\d\.]+\b`)
  21. )
  22. func main() {
  23. tw := tabwriter.NewWriter(os.Stdout, 1, 1, 1, ' ', 0)
  24. br := bufio.NewScanner(os.Stdin)
  25. n := 0
  26. for br.Scan() {
  27. line := br.Bytes()
  28. if benchRe.Match(line) {
  29. n++
  30. line = spacesRe.ReplaceAllLiteral(line, []byte("\t"))
  31. line = numbersRe.ReplaceAllFunc(line, func(n []byte) []byte {
  32. return []byte(fmt.Sprintf("%12s", n))
  33. })
  34. tw.Write(line)
  35. tw.Write([]byte("\n"))
  36. } else if n > 0 && bytes.HasPrefix(line, []byte("ok")) {
  37. n = 0
  38. tw.Flush()
  39. fmt.Printf("%s\n\n", line)
  40. }
  41. }
  42. tw.Flush()
  43. }