-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc.go
More file actions
45 lines (32 loc) · 882 Bytes
/
doc.go
File metadata and controls
45 lines (32 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// A Go Package to benchmark code snippets.
// Get Started
// Creating a benchmark object with 5 iterations
//b := benchmark.NewBenchmark("measuring quicksort algorithm", func() {
// n := quicksort([]int{2312, 212, 2, 31, 33, 0, 23})
// fmt.Println(n)
// }, 5, benchmark.Micro, benchmark.Nano) // more options: see Benchmark.go
// Creating a benchmark stat object
//bs := stats.NewBenchmarkStat(b, stats.All) // more options: see stats.StatType
// Printing stat
//bs.PrintStats()
/* Demo Function
func quicksort(a []int) []int {
if len(a) < 2 {
return a
}
left, right := 0, len(a)-1
pivot := rand.Int() % len(a)
a[pivot], a[right] = a[right], a[pivot]
for i := range a {
if a[i] < a[right] {
a[left], a[i] = a[i], a[left]
left++
}
}
a[left], a[right] = a[right], a[left]
quicksort(a[:left])
quicksort(a[left+1:])
return a
}
*/
package benchmark