This is my first post here ... Please think I'm a hobby programmer.
Problem:
My goal is to improve the performance of my code. The program uses only 65% of the processor and 500 MB of memory. There is another 800 MB of free physical memory available for the program, and about 30% of the processor is idling. I don’t know where there can be a bottleneck for further use of resources and increase of code performance.
Background:
I wrote a program that is a massive testing of a financial algorithm. This algorithm has a number of parameters, and I'm trying to find the best combination of parameters. To do this, I run it for all possible combination of parameters.
This algorithm has an input data series. It iterates through a series of data and gives a result.
Therefore, for this, I introduced the algorithm code into the Parallel.Foreach loop, which runs once for each combination of parameters. The critical code for optimization is a loop.
Since the code is very long, I post the framework:
...
class candle : IComparable<candle>
{
public double open;
public double high;
...40 more
}
class param : IComparable<param>
{
public int par1;
public int par2;
public int par3;
... a few more
}
{
List<candle> sourceCandleList = new List<candle>();
List<param> paramList = new List<param>(1000000);
}
Parallel.ForEach(paramList,
p =>
{
List<candle> CandleList = new List<candle>(sourceCandleList.Count);
foreach (var cndl in sourceCandleList)
{
candle c = new candle();
c.open = cndl.open;
c.high = cndl.high;
...
}
}
140 000 . sourceCandleList 2.000 . , 2.000 , . , GC 200 . 1 Parallel.ForEach 80 . .
, GC , CandleList , . , , . , , , TryEnter, ?
EDITI did not clearly say that the program first generates 2 lists: sourceCandleList and paramList. Then they no longer change as soon as they are completed. After these 2 lists are completely filled, the program starts checking the algorithm: sourceCandleList is the input, and one record from paramList is the set of applied parameters. The problem is that the program defines a new CandleList each time. so i need something like:ConcurrentQueue<List<candle>> ListOfCanldes = new ConcurrentQueue<List<candle>>();
However, I cannot understand the correct syntax.
Questions:Why is the processor memory not fully used? Am I reaching maximum read / write speed of memory ??How can I avoid GC program slowdowns?How can I find out how much time I am losing due to the GC?How to increase productivity?