Reputation: 41
how can I calculate the processing time, for example for copying a file from 1 folder to another? opening a web browser or calculator. the command is given to c# by a batch file the c#first read this file execute it and tell me the time span of each process.
Upvotes: 1
Views: 649
Reputation: 37020
A stopwatch is best for calculating elapsed time
stopwatch sw = new stopwatch;
sw.Start();
// do something here that you want to measure
sw.Stop();
// Get the elapsed time as a TimeSpan
TimeSpan ts = sw.Elapsed;
// Format and display the TimeSpan
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
Console.WriteLine("That took: {0}", elapsedTime);
Upvotes: 1
Reputation: 381
If it's only the processing time AFTER the process, so you need just to use a StopWatch. Create and start a StopWatch just after the process beggining and stop the watch when the process end, then you can get the elapsed time from the StopWatch.
But if you want to predict the time that a process is gonna take, then you can just estimate from previous process times if it's a more fixed-time process or elaborate some relationship about the parameters and the time consuming of the process.
Maybe you can use this link to help you out.
Upvotes: 0