Skip to content

Instantly share code, notes, and snippets.

@eapache
Last active February 14, 2016 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eapache/580b7dbd8800fe9a3234 to your computer and use it in GitHub Desktop.
Save eapache/580b7dbd8800fe9a3234 to your computer and use it in GitHub Desktop.
Sample App to Profile
package main
import (
"fmt"
"log"
"os"
"runtime/pprof"
)
func main() {
f, err := os.Create("profile.out")
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer func() {
pprof.StopCPUProfile()
if err := f.Close(); err != nil {
log.Fatal(err)
}
}()
for i := 0; i < 10000; i++ {
doIt(i)
}
}
func doIt(i int) {
out := ""
for j := 0; j < i; j++ {
if i%2 == 0 {
out += "X"
}
if j%5 == 0 {
out += "Y"
}
}
fmt.Println(i)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment