<table><tr><td style="">dfaure accepted this revision.<br />dfaure added a comment.<br />This revision is now accepted and ready to land.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D10857" rel="noreferrer">View Revision</a></tr></table><br /><div><div><p>" it does suck a little that qSort beats std::sort."<br />
I was curious whether that was true, so I ran Mark's benchmark, with a few fixes: one more zero in the number of items for the vectors, because there was too much variation in numbers when measuring something that lasts around 500ms, and I looped over the two sorting methods, to avoid having to run the benchmark multiple times (because I'm lazy, and because the first iteration seems to have some cold cache effect, the later ones are faster). <a href="http://www.davidfaure.fr/2018/qsort_performance.cpp" class="remarkup-link" target="_blank" rel="noreferrer">http://www.davidfaure.fr/2018/qsort_performance.cpp</a></p>

<p>That gives me pretty stable results.<br />
In release mode:</p>

<div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="text" data-sigil="remarkup-code-block"><pre class="remarkup-code" style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; padding: 12px; margin: 0; background: rgba(71, 87, 120, 0.08);">"qSort took: 4710 ms"
"std::sort took: 4818 ms"
"qSort took: 4600 ms"
"std::sort took: 4737 ms"
"qSort took: 4610 ms"
"std::sort took: 4739 ms"
"qSort took: 4585 ms"
"std::sort took: 4735 ms"
"qSort took: 4592 ms"
"std::sort took: 4748 ms"
"qSort took: 4644 ms"
"std::sort took: 4736 ms"
"qSort took: 4605 ms"
"std::sort took: 4767 ms"</pre></div>

<p>I ran both sorting algos (in RelWithDebInfo mode) in perf+hotspot to find out where the difference comes from, but I see nothing conclusive. std::sort goes via swap<QString,QString> which calls QString::swap(QString&) which calls qSwap(pointers) while qSort is able to call qSwap(pointers) directly, but that's all inline, shouldn't make a difference, I would expect. So it must be the sorting algorithm itself. Oh well, not much we can do, apart from, well, comparing libstdc++ and libc++, another day :)</p>

<p>(Curiously, in debug mode, qSort is much slower than std::sort (9s vs 7.6s).)</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R241 KIO</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D10857" rel="noreferrer">https://phabricator.kde.org/D10857</a></div></div><br /><div><strong>To: </strong>jtamate, Frameworks, dfaure, markg<br /><strong>Cc: </strong>markg, apol, michaelh<br /></div>