Monday, July 27, 2009

How Can I Calculate The Program Elapsed Time In Details Using C# .NET?

I need to calculate elapsed time in details (System CPU Time %26amp; User CPU Time %26amp; I/O Time) Using C# .NET 2003 with Framework Ver 1.1. Best Thanks for interesting

How Can I Calculate The Program Elapsed Time In Details Using C# .NET?
System.DateTime tm = System.DateTime.Now;


System.Threading.Thread.Sleep(1000);


System.DateTime tma = System.DateTime.Now;


System.IO.StreamWriter sw = System.IO.File.AppendText("C:\\TimeTest....


sw.WriteLine((((((tma.Hour * (24 * 60 * 1000)) + (tma.Minute * (60 * 1000))) + (tma.Second * 1000)) + tma.Millisecond) - ((((tm.Hour * (24 * 60 * 1000)) + (tm.Minute * (60 * 1000))) + (tm.Second * 1000)) + tm.Millisecond)));


sw.Flush();
Reply:check http://www.pscode.com/ for examples. I don't program in .NET, but I do use that site all the time
Reply:I'm not exactly sure what you mean, but try something like this:





DateTime dtStart = DateTime.Now;





//Do operations here





int iElapsed_Time = DateTime.Now.Millisecond - dtStart.Millisecond;





For each of the measurements you need to take, just set the time before you start it and then when you are done compare to now.


Good luck!


No comments:

Post a Comment