You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A bit of benchmarking seems to show that raw I/O in Python3.2 is about half the speed as in Python2.7 for the kinds of writes we're doing in the GPIO library.
The following timings were done on the 3.6.11 kernel.
nat@raspberrypi $ python3.2 -m timeit -s 'out=open("/dev/null", "w"); s="1\n"' "out.write(s)"
100000 loops, best of 3: 11.7 usec per loop
nat@raspberrypi $ python2.7 -m timeit -s 'out=open("/dev/null", "w"); s="1\n"' "out.write(s)"
100000 loops, best of 3: 5.9 usec per loop
Oddly, opening in binary mode and writing bytes is slower than writing text:
nat@raspberrypi $ python2.7 -m timeit -r 10 -s 'out=open("/dev/null", "wb"); bs=b"1\n"' "out.write(bs)"
100000 loops, best of 10: 12.5 usec per loop
nat@raspberrypi $ python3.2 -m timeit -r 10 -s 'out=open("/dev/null", "wb"); bs=b"1\n"' "out.write(bs)"
100000 loops, best of 10: 15 usec per loop
Converting from numeric or boolean to text is also a bit slower in Python3.2.
nat@raspberrypi $ python2.7 -m timeit "str(1)"
100000 loops, best of 3: 4.45 usec per loop
nat@raspberrypi $ python3.2 -m timeit "str(1)"
100000 loops, best of 3: 5.52 usec per loop
nat@raspberrypi $ python3.2 -m timeit -r 10 "str(True)"
100000 loops, best of 10: 5.34 usec per loop
nat@raspberrypi $ python2.7 -m timeit -r 10 "str(True)"
100000 loops, best of 10: 4.64 usec per loop
Activity
npryce commentedon Jan 6, 2013
A bit of benchmarking seems to show that raw I/O in Python3.2 is about half the speed as in Python2.7 for the kinds of writes we're doing in the GPIO library.
The following timings were done on the 3.6.11 kernel.
nat@raspberrypi $ python3.2 -m timeit -s 'out=open("/dev/null", "w"); s="1\n"' "out.write(s)"
100000 loops, best of 3: 11.7 usec per loop
nat@raspberrypi $ python2.7 -m timeit -s 'out=open("/dev/null", "w"); s="1\n"' "out.write(s)"
100000 loops, best of 3: 5.9 usec per loop
Oddly, opening in binary mode and writing bytes is slower than writing text:
nat@raspberrypi $ python2.7 -m timeit -r 10 -s 'out=open("/dev/null", "wb"); bs=b"1\n"' "out.write(bs)"
100000 loops, best of 10: 12.5 usec per loop
nat@raspberrypi $ python3.2 -m timeit -r 10 -s 'out=open("/dev/null", "wb"); bs=b"1\n"' "out.write(bs)"
100000 loops, best of 10: 15 usec per loop
Converting from numeric or boolean to text is also a bit slower in Python3.2.
nat@raspberrypi $ python2.7 -m timeit "str(1)"
100000 loops, best of 3: 4.45 usec per loop
nat@raspberrypi $ python3.2 -m timeit "str(1)"
100000 loops, best of 3: 5.52 usec per loop
nat@raspberrypi $ python3.2 -m timeit -r 10 "str(True)"
100000 loops, best of 10: 5.34 usec per loop
nat@raspberrypi $ python2.7 -m timeit -r 10 "str(True)"
100000 loops, best of 10: 4.64 usec per loop