File: bench_test.go

package info (click to toggle)
golang-github-facebookgo-stack 0.0~git20160209.0.7517733-10
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 108 kB
  • sloc: makefile: 4
file content (65 lines) | stat: -rw-r--r-- 1,151 bytes parent folder | download | duplicates (3)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package stack_test

import (
	"fmt"
	"runtime"
	"sync"
	"testing"

	"github.com/facebookgo/stack"
)

func BenchmarkCallersMulti(b *testing.B) {
	for i := 0; i < b.N; i++ {
		stack.CallersMulti(0)
	}
}

func BenchmarkCallers(b *testing.B) {
	for i := 0; i < b.N; i++ {
		stack.Callers(0)
	}
}

func BenchmarkCaller(b *testing.B) {
	for i := 0; i < b.N; i++ {
		stack.Caller(0)
	}
}

func BenchmarkRuntimeCallersReusePCS(b *testing.B) {
	pcs := make([]uintptr, 32)
	for i := 0; i < b.N; i++ {
		runtime.Callers(0, pcs)
	}
}

func BenchmarkRuntimeCallersMakePCS(b *testing.B) {
	for i := 0; i < b.N; i++ {
		pcs := make([]uintptr, 32)
		runtime.Callers(0, pcs)
	}
}

func BenchmarkRuntimeCallersFixedPCS(b *testing.B) {
	for i := 0; i < b.N; i++ {
		var pcs [32]uintptr
		runtime.Callers(0, pcs[:])
	}
}

func BenchmarkRuntimeCallersSyncPool(b *testing.B) {
	pool := sync.Pool{New: func() interface{} { return make([]uintptr, 32) }}
	for i := 0; i < b.N; i++ {
		pcs := pool.Get().([]uintptr)
		runtime.Callers(0, pcs[:])
		pcs = pcs[0:]
		pool.Put(pcs)
	}
}

func BenchmarkSprintf(b *testing.B) {
	for i := 0; i < b.N; i++ {
		fmt.Sprintf("hello")
	}
}