-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdio_bmark_test.go
74 lines (68 loc) · 1.29 KB
/
dio_bmark_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
// Copyright © 2017 Kent Gibson <[email protected]>.
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
//
// Test suite for dio module.
//
// Tests use J8 pins 7 (mostly) and 15 and 16 (for looped tests)
//
package gpio
import (
"testing"
"github.com/stretchr/testify/assert"
)
func BenchmarkSysfsRead(b *testing.B) {
assert.Nil(b, Open())
defer Close()
pin := NewPin(J8p7)
// setup sysfs
err := export(pin)
assert.Nil(b, err)
defer unexport(pin)
f, err := openValue(pin)
assert.Nil(b, err)
defer f.Close()
r := make([]byte, 1)
r[0] = 0
for i := 0; i < b.N; i++ {
f.Read(r)
}
}
func BenchmarkSysfsWrite(b *testing.B) {
assert.Nil(b, Open())
defer Close()
pin := NewPin(J8p7)
// setup sysfs
err := export(pin)
assert.Nil(b, err)
defer unexport(pin)
f, err := openValue(pin)
assert.Nil(b, err)
defer f.Close()
r := "0"
for i := 0; i < b.N; i++ {
f.WriteString(r)
}
}
func BenchmarkSysfsToggle(b *testing.B) {
assert.Nil(b, Open())
defer Close()
pin := NewPin(J8p7)
// setup sysfs
err := export(pin)
assert.Nil(b, err)
defer unexport(pin)
f, err := openValue(pin)
assert.Nil(b, err)
defer f.Close()
r := "0"
for i := 0; i < b.N; i++ {
if r == "0" {
r = "1"
} else {
r = "0"
}
f.WriteString(r)
}
}