Hi,
I am enjoying my new found gift (at the right time of the year) that is QCustomPlot. Usually I have large sets of data either in the form of std::vector
or const double *
data pointers. I have implemented the following method and it works just fine:
QVector<double> qxVals = QVector<double>::fromStdVector(xVals); QVector<double> qyVals = QVector<double>::fromStdVector(yVals); qcpGraph->setData(qxVals, qyVals, true); // already sorted
There is memory and cost associated with conversion from
std::vector
to QVector
, then QCPGraph
internally converts it to a list of QCPGraphData
. I am calling this method 1.
I see that there are 2 other ways we can do this. This is Method 2 (pseudo-code to keep it short):
QVector<QCPGraphData> qcpvGraphData = ::fromStdVectors(xVals, yVals); qcpSharedPointerGraphDataContainer->set (qcpvGraphData, true); qcpGraph->setData(qcpSharedPointerGraphDataContainer, true);
Method 3 (again pseudo-code, let's not worry about the syntax):
for_each (xVal, yVal) in (xVals, yVals) { qcpSharedPointerGraphDataContainer->add(QCPGraphData{xVal, yVal}); // does add implement emplace / std::move idioms? } qcpGraph->setData(qcpSharedPointerGraphDataContainer, true);
Before I spent time coding methods 2 and 3 in order to assess the relative performance, I thought I would find out what is the recommended practice for these large data sets.
Clearly in Methods 1 and 2, there is an intermediate copy of QVector<T>
which gets copied into QCPGraphDataContainer eventually. But in Method 3, sorting has to be done in the add
method. Of course it would be nice to have add(QCPGraphData&&, bool)
to gain some performance.
Any thoughts would be helpful. Thanks.