Created
November 6, 2017 11:20
-
-
Save cowens/6e60c29ad55b173bb71f69fc354bad3e to your computer and use it in GitHub Desktop.
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 waster2() int { | |
j := 0; | |
for i := 0; i < 100; i++ { | |
j += waster1() | |
} | |
return j | |
} | |
func waster1() int { | |
j := 0; | |
for i := 0; i < 10000; i++ { | |
j++ | |
} | |
return j | |
} | |
func main() { | |
f, err := os.Create("cpu.prof") | |
if err != nil { | |
log.Fatal("could not create CPU profile: ", err) | |
} | |
if err := pprof.StartCPUProfile(f); err != nil { | |
log.Fatal("could not start CPU profile: ", err) | |
} | |
defer pprof.StopCPUProfile() | |
j := waster2() | |
fmt.Println(j) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment