views:

137

answers:

5

i am creating project in c#.net. my execution process is very slow. i also found the reason for that.in one method i copied the values from one list to another.that list consists more 3000values for every row . how can i speed up this process.any body help me

for (int i = 0; i < rectTristrip.NofStrips; i++)
            {
                VertexList verList = new VertexList();
                verList = rectTristrip.Strip[i];
                GraphicsPath rectPath4 = verList.TristripToGraphicsPath();
                for (int j = 0; j < rectPath4.PointCount; j++)
                {
                    pointList.Add(rectPath4.PathPoints[j]);
                }

            }

This is the code slow up my procees.Rect tristirp consists lot of vertices each vertices has more 3000 values..

+3  A: 

A profiler will tell you exactly how much time is spent on which lines and which are most important to optimize. Red-gate makes a very good one.

http://www.red-gate.com/products/ants_performance_profiler/index.htm

Sam
I agree with Sam. Another very good profiler: http://www.jetbrains.com/profiler/. you have a 30-days free trial
PierrOz
A: 

Like musicfreak already mentioned you should profile your code to get reliable result on what's going on. But some processes are just taking some time.

In some way you can't get rid of them, they must be done. The question is just: When they are neccessary? So maybe you can put them into some initialization phase or into another thread which will compute the results for you, while your GUI is accessible to your users.

In one of my applications i make a big query against a SQL Server. This task takes a while (built up connection, send query, wait for result, putting result into a data table, making some calculations on my own, presenting the results to the user). All of these steps are necessary and can't be make any faster. But they will be done in another thread while the user sees in the result window a 'Please wait' with a progress bar. In the meantime the user can already make some other settings in the UI (if he likes). So the UI is responsive and the user has no big problem to wait a few seconds.

So this is not a real answer, but maybe it gives you some ideas on how to solve your problem.

Oliver
A: 

You can split the load into a couple of worker threads, say 3 threads each dealing with 1000 elements. You can synchronize it with AutoResetEvent

Vladimir Georgiev
That would result in a speedup in multicore systems only.
chriszero
Yes, and even with multicores it wouldn't do you much good in a busy web server environment. The .NET 4.0 `Parallel.For` has much less overhead, and would be a much better pick.
Steven
But the .NET 4.0 is still in beta.
Vladimir Georgiev
A: 

Some suggestions, even though I think the bulk of the work is in TristripToGraphicsPath():

   // Use rectTristrip.Strip.Length instead of NoOfStrips
   // to let the JIT eliminate bounds checking
   // .Count if it is a list instead of array
   for (int i = 0; i < rectTristrip.Strip.Length; i++)
   {
       VertexList verList = rectTristrip.Strip[i]; // Removed 'new'
       GraphicsPath rectPath4 = verList.TristripToGraphicsPath();

       // Assuming pointList is infact a list, do this:
       pointList.AddRange(rectPath4.PathPoints);
       // Else do this:

       // Use PathPoints.Length instead of PointCount
       // to let the JIT eliminate bounds checking
       for (int j = 0; j < rectPath4.PathPoints.Length; j++)
       {
           pointList.Add(rectPath4.PathPoints[j]);
       }
   }
Robert Jeppesen
A: 

And maybe verList = rectTristrip.Strip[i]; // Removed 'VertexList' to save some memory Define variable VertexList verList above loop.

raf
That does not save you any memory unless VertexList is a value type, which I doubt.
Robert Jeppesen
Yes, you're right.
raf