Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: pfc::sort much slower than qsort_s (Read 2326 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

pfc::sort much slower than qsort_s

i was having some very slow sorting problems using pfc::sort, which I couldnt explain, so i tried qsort_s instead.
Yes I am using 2007.02.04 SDK.

Results of my tests:
Code: [Select]
comp1, stabiliser:
profiler: compeid                                          -         51547650 cycles (executed 98769 times, 521 average)

comp2, stabiliser (*):
profiler: compeid                                          -       3693988890 cycles (executed 7147158 times, 516 average)

comp2, no stabiliser:
profiler: compeid                                          -         61666740 cycles (executed 98769 times, 624 average)

comp2, q_sort_s, stabiliser (*):
profiler: compeid                                          -         98539020 cycles (executed 168519 times, 584 average)

comp2, q_sort_s, no stabiliser:
profiler: compeid                                          -         12529060 cycles (executed 18501 times, 677 average)
Here the profiler is counting/measuring the calls to the comparison function, across a few passes, and comp1 and comp2 are two different comparison funcs.

I marked the cases I am/was actually using with (*). In that case pfc::sort is ~37x slower (!)

this is comp1
Code: [Select]
    static int g_compare_episodeid(const t_sort_entry & item1, const t_sort_entry & item2)
    {
        int ret = lstrcmpi(item1.episode, item2.episode);
                
        return ret;
    }


this is comp2
Code: [Select]
    static int g_compare_episodeid(const t_sort_entry & item1, const t_sort_entry & item2)
    {
        int ret = lstrcmpi(item1.episode, item2.episode);
        
        if (ret)
        {
            int l1 = item1.episode.length(1);
            int l2 = item2.episode.length(1);
            if (!l1 || !l2)
                return l1 ? -1 : 1;
        }
        
        return ret;
    }


and dataset is basically {"","","",.....,"","E06","",.....,""} (without quotes), size about 3000 entries.

I didnt spend too much time verifying the results/using better test method, but rather switching to qsort_s and the end sort result is the same and obviously much faster so I don't think I did anything wrong, but you never know. I am using VS2005 SP1 Vista Update.

Bye
.