Document debug.Timer

This commit is contained in:
Joe Mooring
2023-10-30 09:32:06 -07:00
committed by Bjørn Erik Pedersen
parent 28e2388c2f
commit 708c351c4c
3 changed files with 45 additions and 5 deletions
+40
View File
@@ -0,0 +1,40 @@
---
title: debug.Timer
description: Creates a named timer that reports elapsed time to the console.
categories: [functions]
keywords: []
menu:
docs:
parent: functions
function:
aliases: []
returnType: debug.Timer
signatures: [debug.Timer NAME]
relatedFunctions: []
---
{{< new-in "0.120.0" >}}
Use the `debug.Timer` function to determine execution time for a block of code, useful for finding performance bottlenecks 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
```
+4 -4
View File
@@ -34,8 +34,8 @@ aliases: [/functions/hugo]
`hugo.Generator`
: (`template.HTML`) Renders an HTML `meta` element identifying the software that generated the site (e.g., `<meta name="generator" content="Hugo 0.112.0">`).
`hugo.GoVersion`
: (`string`) The Go version used to compile the Hugo binary (e.g., `go1.20.4`). {{< new-in "0.101.0" >}}
`hugo.GoVersion` {{< new-in "0.101.0" >}}
: (`string`) The Go version used to compile the Hugo binary (e.g., `go1.20.4`).
`hugo.IsDevelopment` {{< new-in "0.120.0" >}}
: (`bool`) Returns `true` if `hugo.Environment` is "development".
@@ -52,8 +52,8 @@ aliases: [/functions/hugo]
`hugo.Version`
: (`hugo.VersionString`) The current version of the Hugo binary (e.g., `0.112.1`).
`hugo.WorkingDir`
: (`string`) The project working directory (e.g., `/home/user/projects/my-hugo-site`). {{< new-in "0.112.0" >}}
`hugo.WorkingDir` {{< new-in "0.112.0" >}}
: (`string`) The project working directory (e.g., `/home/user/projects/my-hugo-site`).
## hugo.Deps
+1 -1
View File
@@ -113,7 +113,7 @@ You can load a custom font if needed. Load the font as a Hugo `Resource` and set
## Padding
{{< new-in "0.120.0" >}}
{{< new-in "0.120.0" >}}
Padding creates a filter that resizes the image canvas without resizing the image. The last argument is the canvas color, expressed as an RGB or RGBA [hexadecimal color]. The default value is `ffffffff` (opaque white). The preceding arguments are the padding values, in pixels, using the CSS [shorthand property] syntax. Negative padding values will crop the image.