What is the best way to sort a collection while updating a progress bar? Currently I have code like this:
for (int i = 0; i < items.size(); i++)
{
pro
I may have missed something because nobody else has mentioned it, but it sounds like the runtime types of your source List
object is not an implementor of RandomAccess and therefore your Collections.binarySearch
invocation is running in O(n) time. That would slow things down quite a bit, very noticeably so, when you so much as double the number of items to sort.
And furthermore, if you are using for example a LinkedList
for sortedItems
then insertion is also O(n).
If that's the case, it makes perfect sense that when you go from 1 million to 2 million items, your expected time will also roughly double.
To diagnose which of the 2 List
objects is problematic
items
; try using a different container, something tree-ish or hash-ysortedItems
; same advice as aboveNote that it can be both List
s that are causing the slowdown. Also this has nothing to do with a progress bar. The problem you described is algorithmic with respect to the sorting, not the updating of a progress bar.