# Would make slower when with \`-\` character in hugo snippet?

**URL:** <https://discourse.gohugo.io/t/would-make-slower-when-with-character-in-hugo-snippet/42043>\
**Category:** support\
**Created:** [December 23, 2022, 1:48am UTC](https://discourse.gohugo.io/t/would-make-slower-when-with-character-in-hugo-snippet/42043 "2022-12-23T01:48:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![elkan1788](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/elkan1788/32/13378_2.png) [@elkan1788](https://discourse.gohugo.io/u/elkan1788)\
**Post date:** [December 23, 2022, 1:48am UTC](https://discourse.gohugo.io/t/would-make-slower-when-with-character-in-hugo-snippet/42043/1 "2022-12-23T01:48:50Z")

</div>

Hi guys:

As we known Hugo snippet support use `-` character trim space, it’s useful generate pretty code of HTML. But I want to know is there will make hugo generate site static code more slower?

As below code sample:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/3X/e/f/ef5b66a81f03e109968672528294fd8901583f30.png)  
Question: Those code with `-` character will make generate speed more slower?

How about your think?

---

<div class="post-metadata">

**Author:** ![bwintx](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bwintx/32/10450_2.png) [@bwintx](https://discourse.gohugo.io/u/bwintx)\
**Post date:** [December 23, 2022, 12:27pm UTC](https://discourse.gohugo.io/t/would-make-slower-when-with-character-in-hugo-snippet/42043/2 "2022-12-23T12:27:32Z")

</div>

Have never noticed any difference, and that’s in a repository with hundreds of files.

---

<div class="post-metadata">

**Author:** ![elkan1788](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/elkan1788/32/13378_2.png) [@elkan1788](https://discourse.gohugo.io/u/elkan1788)\
**Post date:** [December 23, 2022, 12:43pm UTC](https://discourse.gohugo.io/t/would-make-slower-when-with-character-in-hugo-snippet/42043/3 "2022-12-23T12:43:56Z")

</div>

Not yeah, the theme source files is small under hundred, but if the content files of blog articles too much, I think the generate speed would be slow down.

> But I don’t know about Go language, so can’t make sure is the block `{{- /* Some logic */ -}}` slower than `{{/* Some logic */}}` , maybe some can help me find the answer, thanks.

---

<div class="post-metadata">

**Author:** ![razon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/razon/32/14882_2.png) [@razon](https://discourse.gohugo.io/u/razon)\
**Post date:** [December 23, 2022, 1:00pm UTC](https://discourse.gohugo.io/t/would-make-slower-when-with-character-in-hugo-snippet/42043/4 "2022-12-23T13:00:19Z")

</div>

I wrote a simple benchmark.

```go
var t1 = template.Must(template.New("t1").Parse(`"{{23 }} < {{ 45}}"`))
var t2 = template.Must(template.New("t2").Parse(`"{{23 -}} < {{- 45}}"`))

```

```bash
✗ go test -bench .
goos: linux
goarch: amd64
pkg: github.com/razonyang/go-lab
cpu: 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
BenchmarkT1-16 688731 1590 ns/op
BenchmarkT2-16 649561 1649 ns/op
PASS
ok github.com/razonyang/go-lab 2.208s
✗ go test -bench .
goos: linux
goarch: amd64
pkg: github.com/razonyang/go-lab
cpu: 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
BenchmarkT1-16 693091 1619 ns/op
BenchmarkT2-16 699934 1642 ns/op
PASS
ok github.com/razonyang/go-lab 2.312s
✗ go test -bench .
goos: linux
goarch: amd64
pkg: github.com/razonyang/go-lab
cpu: 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
BenchmarkT1-16 705924 1639 ns/op
BenchmarkT2-16 701492 1633 ns/op
PASS
ok github.com/razonyang/go-lab 2.342s
✗ go test -bench .
goos: linux
goarch: amd64
pkg: github.com/razonyang/go-lab
cpu: 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
BenchmarkT1-16 692338 1602 ns/op
BenchmarkT2-16 688156 1582 ns/op
PASS
ok github.com/razonyang/go-lab 2.238s
✗ go test -bench .
goos: linux
goarch: amd64
pkg: github.com/razonyang/go-lab
cpu: 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
BenchmarkT1-16 695038 1614 ns/op
BenchmarkT2-16 590240 1712 ns/op
PASS
ok github.com/razonyang/go-lab 2.175s

```

> Less `ns/op` are better.

Source code could be found at [GitHub - razonyang/go-lab: NOTHING HERE](https://github.com/razonyang/go-lab/tree/template-minus-sign-benchmark).

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [December 23, 2022, 1:48pm UTC](https://discourse.gohugo.io/t/would-make-slower-when-with-character-in-hugo-snippet/42043/5 "2022-12-23T13:48:14Z")

</div>

**The difference in build time is noise.**

I have a 10,000 page site. Each page is rendered by layouts/\_default/single.html, which has 100 of these:

```auto
{{- if true -}}

  {{- .Title -}}

{{- end -}}

```

That’s 3 million of these `{{-` and another 3 million of these `-}}`.

I built the 5 site times, with and without whitespace removal.

| &nbsp; | With `{{ }}` | With `{{- -}}` |
| --- | --- | --- |
| Minimum | 4875 ms | 4891 ms |
| Maximum | 5201 ms | 5676 ms |
| Average | 5015 ms | 5111 ms |

---

<div class="post-metadata">

**Author:** ![elkan1788](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/elkan1788/32/13378_2.png) [@elkan1788](https://discourse.gohugo.io/u/elkan1788)\
**Post date:** [December 23, 2022, 1:49pm UTC](https://discourse.gohugo.io/t/would-make-slower-when-with-character-in-hugo-snippet/42043/6 "2022-12-23T13:49:01Z")

</div>

@razon @jmooring  
Thanks for your code, there look seems the code block of `{{/*some logic*/}}` were more better. But not matter it’s smaller different not much effect.

> Hope this post would help more people who notice the generate speed under Hugo engine.
