Last active
December 31, 2015 15:29
-
-
Save shuLhan/1d02353c777a1d154c81 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 ( | |
"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