Because QCustomPlot uses internally a QCPDataMap
(which is a typedef
of QMap<double, QCPData>
) this means that it is using a map to store the actual data sorted by x
coordinates (keys). Unfortunately the QCPGraph::setData(const QVector<double> &x, const QVector<double> &y)
method doesn't take advantage of the fact that samples could be ordered and doesn't use the insertion hint, so this improved results significantly:
QCPDataMap *data = new QCPDataMap();
size_t len = x.size();
auto xp = std::begin(x);
auto yp = std::begin(y);
while (len--)
data->insertMulti(data->constEnd(), *xp, QCPData(*xp++, *yp++));
graph->setData(data);
I don't think that std::map
s or QMap
s is the best structure to store samples on X,Y graphs because a new allocation and release is done for every entry in the map and we are talking about millions of them. QCustomPlot should implement a custom map class with a custom allocator to avoid these memory issues.