-
Notifications
You must be signed in to change notification settings - Fork 9
Performance boost and simpletest update #8
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
Conversation
…d. change simpletest to use for loop counting ints to avoid floating point math issue
examples/progressbar_simpletest.py
Outdated
current_progress = 0.0 | ||
time.sleep(0.01) | ||
for current_progress in range(0, 21): | ||
print("Progress: {}%".format(current_progress * 0.05)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This outputs 0 -> 1%. I changed it to
print("Progress: {}%".format(current_progress * 0.05 * 100))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch thank you. I'll push a new commit to fix this soon.
examples/progressbar_simpletest.py
Outdated
if current_progress >= 1.0: | ||
current_progress = 0.0 | ||
time.sleep(0.01) | ||
for current_progress in range(0, 21): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't entirely understand the range ending in 21 as 100% It's more intuitive to me for 100% to be... well... 100 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I get what you are doing now that i've read through it a few times. I think the prior example was more intuitive to a newbie (myself) as it made me think in percentages but it does expose the float issue. Maybe leave both in as examples?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change allowed us to count by integers instead of floating point numbers. There was some more discussion about it in the #circuitpython channel on discord this morning if you are interested in learning more about it. http://adafru.it/discord
I think you are right though it would be more clear if it ended on 100. however if it counts by 1 it will be somewhat slower than it is now. we can step by 5 in the range loop though to get the same speed. I'll make this change too. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Being just the example, I think the slower counting to 100 makes more sense. Maybe include a comment mentioning performance? Thank you for fixing this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thanks!
Sidebar: I wish the clear (progress_bar.progress = 0.0) was a blank instead of blacking out the progress bar in reverse :) |
Yep I agree with that. I think it's a limitation of the way the progress is made with a bitmap currently. We have recently gotten a new way to draw shapes with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Updating https://github.com/adafruit/Adafruit_CircuitPython_DS3231 to 2.4.0 from 2.3.2: > Merge pull request adafruit/Adafruit_CircuitPython_DS3231#27 from jepler/calibration-and-temperature Updating https://github.com/adafruit/Adafruit_CircuitPython_PCF8523 to 1.5.0 from 1.4.2: > Merge pull request adafruit/Adafruit_CircuitPython_PCF8523#19 from jepler/calibration-registers Updating https://github.com/adafruit/Adafruit_CircuitPython_PM25 to 1.0.2 from 1.0.1: > Merge pull request adafruit/Adafruit_CircuitPython_PM25#3 from dglaude/patch-1 Updating https://github.com/adafruit/Adafruit_CircuitPython_PyPortal to 3.3.0 from 3.2.5: > Merge pull request adafruit/Adafruit_CircuitPython_PyPortal#82 from fede2cr/master Updating https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT to 3.2.2 from 3.2.1: > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#44 from 2bndy5/master Updating https://github.com/adafruit/Adafruit_CircuitPython_ProgressBar to 1.3.0 from 1.2.3: > Merge pull request adafruit/Adafruit_CircuitPython_ProgressBar#8 from FoamyGuy/performance_boost Updating https://github.com/adafruit/Adafruit_CircuitPython_Requests to 1.5.0 from 1.4.3: > Merge pull request adafruit/Adafruit_CircuitPython_Requests#29 from brentru/update-cellular-3g
This addresses concerns raised in #7.
The new progress drawing strategy will try to only change pixels that need it based on the new progress value and the previous progress value.
It turned out that this library was suffering from the same issue going both directions. Running a loop backward through progresses like this:
would result in a similar effect of the drawing slowing down as the progress approaches
0.0
I have implemented the new strategy in both cases of progress moving up and progress moving down.When the progress is moving down the library previously would fill the "empty" portion of the progress bar from left to right so it looked like it was moving "the wrong way" I modified the behavior to fill emptiness from right to left so the progress bar appears to visually "empty" itself in reverse as it gets drawn.
I made one other tweak to the simpletest example script to change it from adding floating point numbers to instead count by integers and multiple by a decimal to get the current progress. This lets us avoid a floating point precision issue that resulted in the progress sometimes getting set to things like
0.54999999
instead of0.55