Skip to content

Instantly share code, notes, and snippets.

@shuLhan
Last active December 31, 2015 15:29
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 shuLhan/1d02353c777a1d154c81 to your computer and use it in GitHub Desktop.
Save shuLhan/1d02353c777a1d154c81 to your computer and use it in GitHub Desktop.
package main
import (
"github.com/pkg/profile"
)
var n = 100000
func SumByIndex(n int) (sum int) {
sliceint := make([]int, n)
for x := 0; x < n; x++ {
sliceint[x] = x
}
for x := 0; x < n; x++ {
sum += sliceint[x]
}
return sum
}
func memProfile() (sum int) {
defer profile.Start(
profile.MemProfile,
profile.ProfilePath("./"),
).Stop()
for x := 0; x < n; x++ {
sum = SumByIndex(n)
}
return
}
func cpuProfile() (sum int) {
defer profile.Start(
profile.CPUProfile,
profile.ProfilePath("./"),
).Stop()
for x := 0; x < n; x++ {
sum = SumByIndex(n)
}
return
}
func main() {
memProfile()
cpuProfile()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment