Skip to content

Instantly share code, notes, and snippets.

@Lupus
Created October 24, 2015 07:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lupus/1c7ab86e696879cf127b to your computer and use it in GitHub Desktop.
Save Lupus/1c7ab86e696879cf127b to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"html/template"
"log"
"time"
)
func b1() {
tmpl := template.New("test")
start := time.Now()
for i := 0; i < 100000; i++ {
tmpl.Parse("Hello, {{.}}!")
}
elapsed := time.Since(start)
log.Printf("Parsing time elapsed: %s", elapsed)
}
func b2() {
tmpl := template.New("test")
start := time.Now()
tmpl.Parse("Hello, {{.}}!")
for i := 0; i < 100000; i++ {
buf := bytes.NewBuffer([]byte{})
tmpl.Execute(buf, "Mr. Smith")
}
elapsed := time.Since(start)
log.Printf("Execution time elapsed: %s", elapsed)
}
func main() {
b1()
b2()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment