-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GPIO slower on Python3 than Python2 #19
Comments
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)" 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)" Converting from numeric or boolean to text is also a bit slower in Python3.2. nat@raspberrypi $ python2.7 -m timeit "str(1)" nat@raspberrypi $ python3.2 -m timeit -r 10 "str(True)" |
See issue #18.
Running in python 2.7 is faster than python 3.2.
!/usr/bin/env python --> 0.1 ms per GPIO change
!/usr/bin/env python3 --> 0.45 ms per GPIO change
I suspect that maybe there's some unnecessary unicode to binary conversion being performed in Python3
The text was updated successfully, but these errors were encountered: