Skip to content

Instantly share code, notes, and snippets.

@bxcodec
Created April 18, 2018 15:09
Show Gist options
  • Select an option

  • Save bxcodec/a601e4bc5e9790655ec4c2d5a4d7aeea to your computer and use it in GitHub Desktop.

Select an option

Save bxcodec/a601e4bc5e9790655ec4c2d5a4d7aeea to your computer and use it in GitHub Desktop.
cpu_profiling golang
package main
import (
"fmt"
"log"
"os"
_runtime "runtime/pprof"
)
var (
cpuProfile = "cpu.prof"
)
func main() {
// Create file to stored the profiling
cpuProf, err := os.Create(cpuProfile)
if err != nil {
log.Fatal(err)
}
defer cpuProf.Close()
_runtime.StartCPUProfile(cpuProf)
defer _runtime.StopCPUProfile()
ProcessBigArray()
}
func ProcessBigArray() {
for i := 0; i < 10000; i++ {
arr := bigArray()
if arr == nil {
fmt.Println("Array is Nil")
}
}
}
func bigArray() *[]int {
s := make([]int, 1000000)
return &s
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment