Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

im trying to time how much processing a method of my application does. as soon as the method executes , i have a time span :

 

this.processingStart = System.DateTime.Now;// start of processing duration

 

i have the same at the end of the method. i simply take the start time from the finish time, and i should get the total time taken , but i always get 0.

i have a line like:

 

TimeSpan timetaken = processingFinish.Subtract(processingStart);

 

int time = timeTaken.InMiliseconds();

 

is there something up with timespans that cause this, or can anyone tell me a reason why this is happening?

Edited by fguihen
Posted

TimeSpan timeTake = DateTime.Now.Subtract(processingStart);

int time = Convert.ToInt32(timeTake.TotalMilliseconds);

- or -

TimeSpan timeTake = DateTime.Now - processingStart;

int time = Convert.ToInt32(timeTake.TotalMilliseconds);

 

should do the trick, I don't know when processingFinish is set, or what type it is, so I'm assuming it's of type DateTime.

Posted
If you use the system time, make sure you dont run anything else. For instance, running the task manager will regularly give you several milliseconds extra time before your routine is finished. This is because your application is preempted by the OS and the CPU is given to the taskmanager. I don't know if you can somehow get the processing time of an application (like the taskamanager can show) but that would be a safer value to use as it isnt influence by other applications or the OS that do stuff.
Nothing is as illusive as 'the last bug'.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...