diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-06-01 12:00:47 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-06-01 12:00:47 +0200 |
commit | 08a10e5d14669738392db1c41d8b3219c777b234 (patch) | |
tree | 352124e2088974aeecd6688b32272cb55d22f642 | |
parent | 9fa71c945e761c960c2181ed3ce88395a7c23cac (diff) |
hubolib: Make the site benchmark output more compact
So you can do and get:
```
▶ ./benchSite.sh "YAML,num_pages=10"
Running with BenchmarkSiteBuilding/YAML,num_pages=10
BenchmarkSiteBuilding/YAML,num_pages=10-4 1000 1611261 ns/op 730749 B/op 6458 allocs/op
PASS
ok github.com/spf13/hugo/hugolib 8.168s
```
-rwxr-xr-x | benchSite.sh | 4 | ||||
-rw-r--r-- | hugolib/site_benchmark_test.go | 23 |
2 files changed, 24 insertions, 3 deletions
diff --git a/benchSite.sh b/benchSite.sh index c59453336..78a01c6ab 100755 --- a/benchSite.sh +++ b/benchSite.sh @@ -1,9 +1,9 @@ #!/bin/bash -# Send in a regexp mathing the benchmarks you want to run, i.e. './benchSite.sh "frontmatter=YAML"'. +# Send in a regexp mathing the benchmarks you want to run, i.e. './benchSite.sh "YAML"'. # Note the quotes, which will be needed for more complex expressions. # The above will run all variations, but only for front matter YAML. echo "Running with BenchmarkSiteBuilding/${1}" -go test -run="NONE" -bench="BenchmarkSiteBuilding/${1}" -test.benchmem=true ./hugolib
\ No newline at end of file +go test -run="NONE" -bench="BenchmarkSiteBuilding/${1}$" -test.benchmem=true ./hugolib
\ No newline at end of file diff --git a/hugolib/site_benchmark_test.go b/hugolib/site_benchmark_test.go index 89d821880..6b41b8ba2 100644 --- a/hugolib/site_benchmark_test.go +++ b/hugolib/site_benchmark_test.go @@ -34,7 +34,28 @@ type siteBuildingBenchmarkConfig struct { func (s siteBuildingBenchmarkConfig) String() string { // Make it comma separated with no spaces, so it is both Bash and regexp friendly. - return fmt.Sprintf("frontmatter=%s,num_root_sections=%d,num_pages=%d,tags_per_page=%d,shortcodes=%t,render=%t", s.Frontmatter, s.RootSections, s.NumPages, s.TagsPerPage, s.Shortcodes, s.Render) + // To make it a short as possible, we only shows bools when enabled and ints when >= 0 (RootSections > 1) + sep := "," + id := s.Frontmatter + sep + if s.RootSections > 1 { + id += fmt.Sprintf("num_root_sections=%d%s", s.RootSections, sep) + } + id += fmt.Sprintf("num_pages=%d%s", s.NumPages, sep) + + if s.TagsPerPage > 0 { + id += fmt.Sprintf("tags_per_page=%d%s", s.TagsPerPage, sep) + } + + if s.Shortcodes { + id += "shortcodes" + sep + } + + if s.Render { + id += "render" + sep + } + + return strings.TrimSuffix(id, sep) + } func BenchmarkSiteBuilding(b *testing.B) { |