-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathring_test.go
More file actions
101 lines (88 loc) · 1.78 KB
/
ring_test.go
File metadata and controls
101 lines (88 loc) · 1.78 KB
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
package goliburing
import (
"os"
"testing"
)
func TestNewRing(t *testing.T) {
var queueDepth uint32 = 128
ring, err := NewRing(queueDepth, nil)
if err != nil {
t.Fatal(err)
}
if want, have := queueDepth, ring.QueueDepth(); want != have {
t.Fatalf("queueDepth: want %d, have %d", want, have)
}
}
func TestPrepWriteV(t *testing.T) {
ring, err := NewRing(128, nil)
if err != nil {
t.Fatal(err)
}
f, err := os.OpenFile("tmp", os.O_CREATE|os.O_TRUNC|os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
t.Fatal(err)
}
defer f.Close()
data := make([]byte, 256)
sqe, err := ring.GetEmptySQE()
if err != nil {
t.Fatal(err)
}
sqe.PrepWriteV(int(f.Fd()), data, 0)
ring.Submit()
cqe, err := ring.WaitCQE()
if err != nil {
t.Fatal(err)
}
cqe.Seen()
os.Remove(f.Name())
}
func BenchmarkPrepWriteV(b *testing.B) {
ring, err := NewRing(128, nil)
if err != nil {
b.Error(err)
}
defer ring.Destroy()
f, err := os.OpenFile("tmp-benchmark-prep-write-v", os.O_CREATE|os.O_TRUNC|os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
b.Error(err)
}
defer f.Close()
data := make([]byte, 256)
b.ResetTimer()
for i := 0; i < b.N; i++ {
sqe, err := ring.GetEmptySQE()
if err != nil {
b.Error(err)
return
}
sqe.PrepWriteV(int(f.Fd()), data, 0)
ring.Submit()
cqe, err := ring.WaitCQE()
if err != nil {
b.Error(err)
return
}
cqe.Seen()
}
b.StopTimer()
os.Remove(f.Name())
}
func BenchmarkNormalWrite(b *testing.B) {
f, err := os.OpenFile("/tmp/benchmark-normal-write", os.O_CREATE|os.O_TRUNC|os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
b.Error(err)
}
defer f.Close()
data := make([]byte, 256)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err = f.Write(data)
if err != nil {
b.Error(err)
}
// f.Sync()
}
b.StopTimer()
os.Remove(f.Name())
}