-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmark
executable file
·101 lines (74 loc) · 2.03 KB
/
benchmark
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
#!/usr/bin/env python3
'Simple benchmark for pifaceio against pifacedigitalio.'
# Author: Mark Blakeney, Nov 2020.
import time
import pifaceio
import pifacedigitalio
COUNT = 1000
def report(test, val1, val2):
'Output test results comparison'
ps1 = round(COUNT / val1, 1)
ps2 = round(COUNT / val2, 1)
mult = round(ps1 / ps2, 1)
print()
print(f'pifacedigitalio did {ps2} {test} per second.')
print(f'pifaceio did {ps1} {test} per second.')
print(f'pifaceio {test} is {mult} times faster.')
# Execute pifaceio tests ..
pf = pifaceio.PiFace()
start = time.monotonic()
for c in range(COUNT):
pf.read()
read1 = time.monotonic() - start
start = time.monotonic()
for c in range(COUNT):
if c % 2:
pf.write(0x80)
else:
pf.write(0)
write1 = time.monotonic() - start
pf.close()
pifaceio.init()
start = time.monotonic()
for c in range(COUNT):
pifaceio.digital_read(0)
readc1 = time.monotonic() - start
start = time.monotonic()
for c in range(COUNT):
if c % 2:
pifaceio.digital_write(7, 1)
else:
pifaceio.digital_write(7, 0)
writec1 = time.monotonic() - start
pifaceio.deinit()
# Execute pifacedigitalio tests ..
pf = pifacedigitalio.PiFaceDigital()
start = time.monotonic()
for c in range(COUNT):
pf.input_port.value
read2 = time.monotonic() - start
start = time.monotonic()
for c in range(COUNT):
if c % 2:
pf.leds[7].turn_on()
else:
pf.leds[7].turn_off()
write2 = time.monotonic() - start
pf.deinit_board()
pifacedigitalio.init()
start = time.monotonic()
for c in range(COUNT):
pifacedigitalio.digital_read(0)
readc2 = time.monotonic() - start
start = time.monotonic()
for c in range(COUNT):
if c % 2:
pifacedigitalio.digital_write(7, 1)
else:
pifacedigitalio.digital_write(7, 0)
writec2 = time.monotonic() - start
pifacedigitalio.deinit()
report('input reads', read1, read2)
report('output writes', write1, write2)
report('classic API input reads', readc1, readc2)
report('classic API output reads', writec1, writec2)