This repository has been archived by the owner on Apr 23, 2020. It is now read-only.
/
benchmarks_test.go
129 lines (112 loc) · 2.11 KB
/
benchmarks_test.go
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package rope
import (
"bytes"
"testing"
)
const benchBytesLen = 1 * 1024 * 1024
func getBenchBytes() []byte {
return getRandomBytes(benchBytesLen)
}
func getBenchRope() *Rope {
return NewFromBytes(getBenchBytes())
}
func BenchmarkNew(b *testing.B) {
bytes := getBenchBytes()
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.SetBytes(benchBytesLen)
NewFromBytes(bytes)
}
}
func BenchmarkIndex(b *testing.B) {
r := getBenchRope()
b.ResetTimer()
for i := 0; i < b.N; i++ {
r.Index(512 * 1024)
}
}
func BenchmarkLen(b *testing.B) {
r := getBenchRope()
b.ResetTimer()
for i := 0; i < b.N; i++ {
r.Len()
}
}
func BenchmarkBytes(b *testing.B) {
r := getBenchRope()
b.ResetTimer()
for i := 0; i < b.N; i++ {
r.Bytes()
}
}
func BenchmarkConcat(b *testing.B) {
r1 := getBenchRope()
r2 := getBenchRope()
b.ResetTimer()
for i := 0; i < b.N; i++ {
r1.Concat(r2)
}
}
func BenchmarkSplit(b *testing.B) {
r := getBenchRope()
b.ResetTimer()
for i := 0; i < b.N; i++ {
r.Split(512 * 1024)
}
}
func BenchmarkInsert(b *testing.B) {
r := getBenchRope()
b.ResetTimer()
for i := 0; i < b.N; i++ {
r.Insert(128*1024, []byte("foobar"))
}
}
func BenchmarkDelete(b *testing.B) {
r := getBenchRope()
b.ResetTimer()
for i := 0; i < b.N; i++ {
r.Delete(128*1024, 200*1024)
}
}
func BenchmarkSub(b *testing.B) {
r := getBenchRope()
b.ResetTimer()
for i := 0; i < b.N; i++ {
r.Sub(128*1024, 1024)
}
}
func BenchmarkIter(b *testing.B) {
r := getBenchRope()
b.ResetTimer()
for i := 0; i < b.N; i++ {
r.Iter(0, func([]byte) bool {
return true
})
}
}
func BenchmarkRebalance(b *testing.B) {
for i := 0; i < b.N; i++ {
r := NewFromBytes(nil)
for j := 0; j < 2048; j++ {
r = r.Concat(NewFromBytes([]byte{'x'}))
}
}
}
func BenchmarkIterBackward(b *testing.B) {
r := getBenchRope()
b.ResetTimer()
for i := 0; i < b.N; i++ {
r.IterBackward(r.Len(), func([]byte) bool {
return true
})
}
}
func BenchmarkIterRune(b *testing.B) {
r := NewFromBytes(bytes.Repeat([]byte("foobarbaz"), 1024))
b.ResetTimer()
for i := 0; i < b.N; i++ {
r.IterRune(0, func(ru rune, l int) bool {
return true
})
}
}