Sort a large collection while showing progress

后端 未结 7 799
广开言路
广开言路 2021-01-02 22:58

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         


        
7条回答
  •  迷失自我
    2021-01-02 23:34

    If you're just comparing sort times, print the time before and after the sort.

    Predicting how long a sort in the wild will take is difficult. For some sorts it depends on the ordering of the input. I'd use i/(double) items.size() to generate a ratio of the work done and call it a fine day. You might choose to update the bar every items.size()/100 iterations. There no reason to slam the poor progress bar with useless updates.

提交回复
热议问题