I’m trying to merge xvalues of two data series (both must have equals xvalues).
First, i get a keys – collection of different keys, and want to insert this keys into second data series.
using (ds.SuspendUpdates())
{
int keyIndex = 0;
int dsIndex = ds.FindIndex(keys[0], SearchMode.RoundUp);
while (dsIndex < ds.XValues.Count)
{
if (keyIndex >= keys.Count) break;
if (ds.XValues[dsIndex] > keys[keyIndex])
{
ds.Insert(dsIndex, keys[keyIndex], Double.NaN);
keyIndex++;
}
dsIndex++;
}
}
But if ds.XValues.Count = 1200000 and keys’s count = 200000, that this method work to much time.
Complexity of this method is O(n), so i want to know what is performance (complexity) of data series insert method?
- Ivan Zakharov asked 9 years ago
- You must login to post comments
Hi Arthur,
Insert performance will be roughly the same as List.Insert, where we have one list for each column. E.g. Date, Open, High, Low, Close are 5 lists.
Insert requires that the underlying list is resized, all elements after the Insert are copied (moved) and the new elements copied (inserted).
DataSeries.InsertRange is a faster and better way to insert than point-by-point insert.
Hope this helps,
Andrew
- Andrew Burnett-Thompson answered 9 years ago
-
Data to insert often don't point-by-point. Is there any way to create a data series with a parameter capacity (like new List(capacity))?
-
Not at this time, no. The append performance is very fast. Inserts require a resize, copy and move operation so are slower than appends. If you can, try to re-write your code to iterate over two series and only use Append in order.
-
Something else you can try is merging to a List List with pre-defined capacity then appending one block using DataSeries.Append(xVaues, yValues). It will use more memory but should be quicker!
- You must login to post comments
Please login first to submit.