forked from romilly/quick2wire-python-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpio-speed
More file actions
executable file
·30 lines (21 loc) · 751 Bytes
/
gpio-speed
File metadata and controls
executable file
·30 lines (21 loc) · 751 Bytes
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
#!/usr/bin/env python3
from datetime import datetime
from quick2wire.gpio import pins, In, Out
from timeit import Timer
def nothin():
pass
def onepass_read():
x = inpin.value
def onepass_toggle():
outpin.value = 1
outpin.value = 0
iterations = 10000
outpin = pins.pin(0, Out)
inpin = pins.pin(1, In)
with inpin, outpin:
overhead = Timer(nothin).timeit(iterations)
readresult = Timer(onepass_read).timeit(iterations)
toggleresult = Timer(onepass_toggle).timeit(iterations)
print("The time to do nothing %d times is %4.3fsec" % (iterations, overhead))
print("The time to read %d times is %4.3fsec" % (iterations, readresult))
print("The time to toggle %d times is %4.3fsec" % (iterations, toggleresult))