Created
October 24, 2015 07:30
-
-
Save Lupus/1c7ab86e696879cf127b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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