blob: ae6c3188fd893fe4aa80676368ed4ff49cdf6c8b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
---
title: debug.Timer
description: Creates a named timer that reports elapsed time to the console.
categories: []
keywords: []
action:
aliases: []
related: []
returnType: debug.Timer
signatures: [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.
```go-html-template
{{ $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.
```sh
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.
```text
INFO timer: name TestSqrt total 12.429355ms
```
|