forked from jmckaskill/go-capnproto
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtextmv_test.go
48 lines (37 loc) · 965 Bytes
/
textmv_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
package capn_test
import (
"math/rand"
"testing"
capn "github.com/glycerine/go-capnproto"
air "github.com/glycerine/go-capnproto/aircraftlib"
)
// highlight how much faster text movement between segments
// is when special casing Text and Data
//
// run this test with capn.go:1334-1341 commented in/out to compare.
//
func BenchmarkTextMovementBetweenSegments(b *testing.B) {
buf := make([]byte, 1<<21)
buf2 := make([]byte, 1<<21)
text := make([]byte, 1<<20)
for i := range text {
text[i] = byte(65 + rand.Int()%26)
}
//stext := string(text)
//fmt.Printf("text = %#v\n", stext)
astr := make([]string, 1000)
for i := range astr {
astr[i] = string(text[i*1000 : (i+1)*1000])
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
seg := capn.NewBuffer(buf[:0])
scratch := capn.NewBuffer(buf2[:0])
ht := air.NewRootHoldsText(seg)
tl := scratch.NewTextList(1000)
for j := 0; j < 1000; j++ {
tl.Set(j, astr[j])
}
ht.SetLst(tl)
}
}