...
1 package match
2
3 import (
4 "sync"
5 "testing"
6 )
7
8 func benchPool(i int, b *testing.B) {
9 pool := sync.Pool{New: func() interface{} {
10 return make([]int, 0, i)
11 }}
12
13 b.RunParallel(func(pb *testing.PB) {
14 for pb.Next() {
15 s := pool.Get().([]int)[:0]
16 pool.Put(s)
17 }
18 })
19 }
20
21 func benchMake(i int, b *testing.B) {
22 b.RunParallel(func(pb *testing.PB) {
23 for pb.Next() {
24 _ = make([]int, 0, i)
25 }
26 })
27 }
28
29 func BenchmarkSegmentsPool_1(b *testing.B) {
30 benchPool(1, b)
31 }
32 func BenchmarkSegmentsPool_2(b *testing.B) {
33 benchPool(2, b)
34 }
35 func BenchmarkSegmentsPool_4(b *testing.B) {
36 benchPool(4, b)
37 }
38 func BenchmarkSegmentsPool_8(b *testing.B) {
39 benchPool(8, b)
40 }
41 func BenchmarkSegmentsPool_16(b *testing.B) {
42 benchPool(16, b)
43 }
44 func BenchmarkSegmentsPool_32(b *testing.B) {
45 benchPool(32, b)
46 }
47 func BenchmarkSegmentsPool_64(b *testing.B) {
48 benchPool(64, b)
49 }
50 func BenchmarkSegmentsPool_128(b *testing.B) {
51 benchPool(128, b)
52 }
53 func BenchmarkSegmentsPool_256(b *testing.B) {
54 benchPool(256, b)
55 }
56
57 func BenchmarkSegmentsMake_1(b *testing.B) {
58 benchMake(1, b)
59 }
60 func BenchmarkSegmentsMake_2(b *testing.B) {
61 benchMake(2, b)
62 }
63 func BenchmarkSegmentsMake_4(b *testing.B) {
64 benchMake(4, b)
65 }
66 func BenchmarkSegmentsMake_8(b *testing.B) {
67 benchMake(8, b)
68 }
69 func BenchmarkSegmentsMake_16(b *testing.B) {
70 benchMake(16, b)
71 }
72 func BenchmarkSegmentsMake_32(b *testing.B) {
73 benchMake(32, b)
74 }
75 func BenchmarkSegmentsMake_64(b *testing.B) {
76 benchMake(64, b)
77 }
78 func BenchmarkSegmentsMake_128(b *testing.B) {
79 benchMake(128, b)
80 }
81 func BenchmarkSegmentsMake_256(b *testing.B) {
82 benchMake(256, b)
83 }
84
View as plain text