From 708c351c4c4fc3288f1e817d3c80eb82630c5f56 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Mon, 30 Oct 2023 09:32:06 -0700 Subject: [PATCH] Document debug.Timer --- content/en/functions/debug/Timer.md | 40 ++++++++++++++++++++++++++++ content/en/functions/hugo/index.md | 8 +++--- content/en/functions/images/index.md | 2 +- 3 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 content/en/functions/debug/Timer.md diff --git a/content/en/functions/debug/Timer.md b/content/en/functions/debug/Timer.md new file mode 100644 index 000000000..cfa2ad6dc --- /dev/null +++ b/content/en/functions/debug/Timer.md @@ -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 +``` diff --git a/content/en/functions/hugo/index.md b/content/en/functions/hugo/index.md index 3f1202481..64ea0db22 100644 --- a/content/en/functions/hugo/index.md +++ b/content/en/functions/hugo/index.md @@ -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., ``). -`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 diff --git a/content/en/functions/images/index.md b/content/en/functions/images/index.md index 07b39f982..a1351f190 100644 --- a/content/en/functions/images/index.md +++ b/content/en/functions/images/index.md @@ -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.