mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-04-26 13:48:49 +08:00

This maintains `direction` and `value` `File`s for each DigitalPin implementation. Instead of Open/Read/Close we now only do Seek/Read, this speeds up Read/Write operations a bit. A silly benchmark on the mock FS gives: benchmark old ns/op new ns/op delta BenchmarkDigitalRead-8 647 7.36 -98.86% benchmark old allocs new allocs delta BenchmarkDigitalRead-8 5 0 -100.00% benchmark old bytes new bytes delta BenchmarkDigitalRead-8 96 0 -100.00%
22 lines
352 B
Go
22 lines
352 B
Go
package sysfs
|
|
|
|
import "testing"
|
|
|
|
func BenchmarkDigitalRead(b *testing.B) {
|
|
fs := NewMockFilesystem([]string{
|
|
"/sys/class/gpio/export",
|
|
"/sys/class/gpio/unexport",
|
|
"/sys/class/gpio/gpio10/value",
|
|
"/sys/class/gpio/gpio10/direction",
|
|
})
|
|
|
|
SetFilesystem(fs)
|
|
pin := NewDigitalPin(10)
|
|
pin.Write(1)
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
pin.Read()
|
|
}
|
|
|
|
}
|