forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Seek to speed up read/write in sysfs
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%
- Loading branch information
Showing
5 changed files
with
127 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters