PS E:\GoSortAlgorithm> go test -bench .
goos: windows
goarch: amd64
pkg: GoSortAlgorithm
cpu: Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz
BenchmarkBubbleSort-6 12 96679492 ns/op 0 B/op 0 allocs/op
BenchmarkSelectSort-6 25 47674376 ns/op 0 B/op 0 allocs/op
BenchmarkInsertSort-6 79 14008396 ns/op 0 B/op 0 allocs/op
BenchmarkShellSort-6 1701 849523 ns/op 0 B/op 0 allocs/op
BenchmarkMergeSort-6 1126 1131423 ns/op 1112708 B/op 9999 allocs/op
BenchmarkQuickSort-6 1872 609207 ns/op 0 B/op 0 allocs/op
BenchmarkHeapSort-6 1016 1200000 ns/op 0 B/op 0 allocs/op
BenchmarkCountSort-6 3242 321729 ns/op 802820 B/op 1 allocs/op
BenchmarkRadixSort-6 918 1285081 ns/op 925213 B/op 560 allocs/op
BenchmarkBucketSort-6 100 10746767 ns/op 160240 B/op 10011 allocs/op
PASS
ok GoSortAlgorithm 14.485s
参考:https://geektutu.com/post/hpg-pprof.html
- 执行benchmark测试并生成profile
go test -bench="Sort$" -cpuprofile="cpu.pprof" .
- 在浏览器中分析cpu/内存性能数据
go tool pprof -http=:11111 cpu.pprof
ps:如果提示 Graphviz 没有安装,则通过
brew install graphviz
(MAC) 或apt install graphviz
(Ubuntu) 即可