QTest: use nth_element to calculate the median
Sorting is O(NlogN) complexity, while nth_element is linear. Change-Id: Ic6596affe183494e87abe7bdaa7c9985f5b7cd58 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
parent
12bd604f24
commit
48586b2bac
@ -1631,13 +1631,14 @@ QBenchmarkResult qMedian(const QList<QBenchmarkResult> &container)
|
|||||||
if (count == 1)
|
if (count == 1)
|
||||||
return container.at(0);
|
return container.at(0);
|
||||||
|
|
||||||
QList<QBenchmarkResult> containerCopy = container;
|
|
||||||
std::sort(containerCopy.begin(), containerCopy.end());
|
|
||||||
|
|
||||||
const int middle = count / 2;
|
const int middle = count / 2;
|
||||||
|
|
||||||
|
QList<QBenchmarkResult> containerCopy = container;
|
||||||
|
const QList<QBenchmarkResult>::iterator begin = containerCopy.begin(), mid = begin + middle, end = containerCopy.end();
|
||||||
|
std::nth_element(begin, mid, end);
|
||||||
|
|
||||||
// ### handle even-sized containers here by doing an aritmetic mean of the two middle items.
|
// ### handle even-sized containers here by doing an aritmetic mean of the two middle items.
|
||||||
return containerCopy.at(middle);
|
return *mid;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct QTestDataSetter
|
struct QTestDataSetter
|
||||||
|
Loading…
x
Reference in New Issue
Block a user