Нема описа

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // sample program that is used to produce some of the files in
  2. // pprof/internal/report/testdata.
  3. package main
  4. import (
  5. "flag"
  6. "fmt"
  7. "log"
  8. "math"
  9. "os"
  10. "runtime/pprof"
  11. )
  12. var cpuProfile = flag.String("cpuprofile", "", "where to write cpu profile")
  13. func main() {
  14. flag.Parse()
  15. f, err := os.Create(*cpuProfile)
  16. if err != nil {
  17. log.Fatal("could not create CPU profile: ", err)
  18. }
  19. if err := pprof.StartCPUProfile(f); err != nil {
  20. log.Fatal("could not start CPU profile: ", err)
  21. }
  22. defer pprof.StopCPUProfile()
  23. busyLoop()
  24. }
  25. func busyLoop() {
  26. m := make(map[int]int)
  27. for i := 0; i < 1000000; i++ {
  28. m[i] = i + 10
  29. }
  30. var sum float64
  31. for i := 0; i < 100; i++ {
  32. for _, v := range m {
  33. sum += math.Abs(float64(v))
  34. }
  35. }
  36. fmt.Println("Sum", sum)
  37. }