hugo/docs/content/en/functions/debug/Timer.md
Bjørn Erik Pedersen 5fd1e74903
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```

Closes #11925
2024-01-27 10:48:57 +01:00

946 B

title description categories keywords action
debug.Timer Creates a named timer that reports elapsed time to the console.
aliases related returnType signatures
debug.Timer
debug.Timer NAME

{{< new-in 0.120.0 >}}

Use the debug.Timer function to determine execution time for a block of code, useful for finding performance bottle necks in templates.

The timer starts when you instantiate it, and stops when you call its Stop method.

{{ $t := debug.Timer "TestSqrt" }}
{{ range seq 2000 }}
  {{ $f := math.Sqrt . }}
{{ end }}
{{ $t.Stop }}

Use the --logLevel info command line flag when you build the site.

hugo --logLevel info

The results are displayed in the console at the end of the build. You can have as many timers as you want and if you don't stop them, they will be stopped at the end of build.

INFO  timer:  name TestSqrt total 12.429355ms