# Testing (timing actually)

**URL:** <https://discourse.gohugo.io/t/testing-timing-actually/30475>\
**Category:** dev\
**Created:** [January 7, 2021, 12:35pm UTC](https://discourse.gohugo.io/t/testing-timing-actually/30475 "2021-01-07T12:35:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [January 7, 2021, 12:35pm UTC](https://discourse.gohugo.io/t/testing-timing-actually/30475/1 "2021-01-07T12:35:39Z")

</div>

I would like to somehow test how various strategies impact Hugo’s build times. Is there a nice way to “hook” somehow into Hugo to get lists of times that certain things need to run? I can read 😉 and I am eager to learn, so linkdrops are ok.

Sample test:

I wonder which one of the following strategies saves/costs more time:

- a configuration value is set in `data/path/to/file.toml`
- method a) loading every time via `{{ site.Data.path/to/file/variable | default "value" }}`
- method b) loads once and return via partialCached
- method c) loads once and save in a scratch variable that is reused
- i run hugo with each method and 100 calls to get that value
- i get some form of output with a time per method

Does Hugo have some form of hooks that a different go script could somehow use to play around? Worst case is of course to let a shell script run a test site multiple times and collect an average.

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [January 7, 2021, 1:09pm UTC](https://discourse.gohugo.io/t/testing-timing-actually/30475/2 "2021-01-07T13:09:00Z")

</div>

I am only aware of the CLI [`--templateMetrics`](https://gohugo.io/troubleshooting/build-performance/#template-metrics) flag, I suppose that you would have to use external tools to run a benchmark.

> [@davidsneighbour](#):
>
> a configuration value is set in `data/path/to/file.toml`

Data Files in great numbers are known to slow down build time see: [Data Files eat memory · Issue #1065](https://github.com/gohugoio/hugo/issues/1065)

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [January 7, 2021, 1:41pm UTC](https://discourse.gohugo.io/t/testing-timing-actually/30475/3 "2021-01-07T13:41:23Z")

</div>

> [@alexandros](#):
>
> I am only aware of the CLI [`--templateMetrics`](https://gohugo.io/troubleshooting/build-performance/#template-metrics) flag

That tag weirdly is in my “I don’t like you”-list 😉 It tells me the following layout file is not cachable (0), but I am not sure if it’s worth pestering the team with a bug report:

```auto
<div class="progress" id="readingprogress">
    <div class="progress-bar"
         id="readingprogress-bg"
         role="progressbar"
         aria-label="Readingprogress"
         aria-valuenow="0"
         aria-valuemin="0"
         aria-valuemax="100"></div>
</div>

```

Of course the timing output on this param might help or even be what I want… I will play around with it. Putting a “method” into a layout and checking on it’s average timing value might be what I want.

> [@alexandros](#):
>
> Data Files in great numbers are known to slow down build

Yeah 😆 I doubled my site creation from about 1 minute to 2 minutes by fragmenting everything into modules (up to 3 levels deep) with their own namespaced data configuration. It feeds my OCD to have everything in the right place, but it costs dearly on the speed.

---

<div class="post-metadata">

**Author:** ![moorereason](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/moorereason/32/592_2.png) [@moorereason](https://discourse.gohugo.io/u/moorereason)\
**Post date:** [January 7, 2021, 6:52pm UTC](https://discourse.gohugo.io/t/testing-timing-actually/30475/4 "2021-01-07T18:52:40Z")

</div>

> [@davidsneighbour](#):
>
> That tag weirdly is in my “I don’t like you”-list 😉 It tells me the following layout file is not cachable (0), but I am not sure if it’s worth pestering the team with a bug report:

Please explain.

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [January 7, 2021, 7:01pm UTC](https://discourse.gohugo.io/t/testing-timing-actually/30475/5 "2021-01-07T19:01:16Z")

</div>

> [@moorereason](#):
>
> Please explain.

That’s all there is. The code above has not one single variable and Hugo says it’s not something to cache. I would expect a 100 but `hugo --templateMetrics` says 0.

---

<div class="post-metadata">

**Author:** ![moorereason](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/moorereason/32/592_2.png) [@moorereason](https://discourse.gohugo.io/u/moorereason)\
**Post date:** [January 7, 2021, 7:09pm UTC](https://discourse.gohugo.io/t/testing-timing-actually/30475/6 "2021-01-07T19:09:57Z")

</div>

I sometimes use a Go benchmark to build the docs site. I suppose you could do the same thing to test changes to a site. Here’s how:

Create a Go test file in the root of the hugo codebase as seen below. Set the flags as needed, but mainly set the `--source` flag to the path of your site:

```auto
package main

import (
        "testing"

        "github.com/gohugoio/hugo/commands"
)

func BenchmarkDocsSite(b *testing.B) {
        flags := []string{
                "--quiet",
                "--source=docs",
                "--renderToMemory",
        }

        for i := 0; i < b.N; i++ {
                r := commands.Execute(flags)
                if r.Err != nil {
                        b.Fatal(r.Err)
                }
        }
}

```

Run the benchmark and save the output to a file. I use `tee` for this:

```auto
go test -bench=. -benchmem -count=5 . | tee baseline.txt

```

Make changes to your project and rerun the benchmark, saving to another file:

```auto
go test -bench=. -benchmem -count=5 . | tee variant-1.txt

```

Install `benchstat` if you don’t have it already (don’t do this while within the Hugo project or it may update your go.mod file):

```auto
go get golang.org/x/perf/cmd/benchstat

```

Use `benchstat` to compare the results:

```auto
benchstat baseline.txt variant-1.txt

```

Curious if this shows you anything useful.

---

<div class="post-metadata">

**Author:** ![moorereason](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/moorereason/32/592_2.png) [@moorereason](https://discourse.gohugo.io/u/moorereason)\
**Post date:** [January 7, 2021, 7:16pm UTC](https://discourse.gohugo.io/t/testing-timing-actually/30475/7 "2021-01-07T19:16:39Z")

</div>

I can’t reproduce this. Can you provide a site that reproduces this?

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [January 8, 2021, 7:01am UTC](https://discourse.gohugo.io/t/testing-timing-actually/30475/8 "2021-01-08T07:01:10Z")

</div>

I added you to my repo. It’s a bit large and moduled.

---

<div class="post-metadata">

**Author:** ![moorereason](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/moorereason/32/592_2.png) [@moorereason](https://discourse.gohugo.io/u/moorereason)\
**Post date:** [January 8, 2021, 4:39pm UTC](https://discourse.gohugo.io/t/testing-timing-actually/30475/9 "2021-01-08T16:39:57Z")

</div>

Bug filed for the cache hint issue:

> <https://github.com/gohugoio/hugo/issues/8125>
>
> As report by @davidsneighbour at https://discourse.gohugo.io/t/30475/3.
> A HTML-only partial shows a cache potential of 0 instead of 100.
> For example:
> \<div class="progress" id="readingprogress"\>
> \<div...
