Uh oh!
There was an error while loading. Please reload this page.
Update sorts/bubble_sort.py - #5802
Conversation
| """ | ||
| length = len(collection) | ||
| for i in range(length - 1): | ||
| for i in reversed(range(length)): |
There was a problem hiding this comment.
Is calling reversed more efficient? I don't think so. Did you do some benchmarks?
There was a problem hiding this comment.
reversed has to be a bit better since the Python heapq.py module uses it.
It also improves code readability. @l3str4nge
There was a problem hiding this comment.
I know but it would be good to know if algorithms performance is better too :) Could you perform any benchmarks before and after refactor?
There was a problem hiding this comment.
Benchmarked with the timeit module:
1000 items:
Before: 0.10902250000071945
After: 0.11019620000297436
5000 items:
Before: 2.8898907999973744
After: 2.844012000001385
10000 items:
Before: 12.34897049999563
After: 11.655540399995516
I tested a bit more locally and sometimes refactored one is better and sometimes it's the original.
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Describe your change:
sorts/bubble_sort.py:bubble_sortfunctionChecklist:
Fixes: #{$ISSUE_NO}.