Last active
February 14, 2016 16:51
-
-
Save eapache/580b7dbd8800fe9a3234 to your computer and use it in GitHub Desktop.
Sample App to Profile
This file contains 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 ( | |
"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