Forum C# Max execution time

Max execution time

Postby knurf » December 7th, 2010, 10:55 am

Hi,

how do you measure your/my maximum execution time? And how much is it? From the dev server get warnings a little randomly, and in waves of 4 or more. Sometimes I get the feeling that thread locks are causing it (a timer is doing much of the work while running in lock).

I have a lengthy initialization of about 500ms or so (if not processed in smaller chunks, then that time will easily 10 fold) on a new room creation and every 5 minutes or so per room. This is to generate a new level.

The process has been broken down into interruptible steps and fired from a Timer delegate, but as my only means of time measurement is the rather inexact DateTime (+/- 10ms or worse?) I can't throttle execution properly and get warnings. How about white listing System.Diagnostics.Stopwatch or anything similar?
knurf
 
Posts: 4
Joined: December 3rd, 2010, 12:51 pm

Re: Max execution time

Postby Oliver » December 16th, 2010, 1:21 pm

Everytime a thread enters your code, a timestamp is set. Periodically, another thread will check if any code has been executing for more than 100ms, and abort it if so.

Generally, you don't want to be anywhere near that limit.

Is StopWatch more accurate than DateTime.Now?

- Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Max execution time

Postby knurf » December 16th, 2010, 4:02 pm

It should be, I get the impression that can use things like QueryPerformanceCounter and friends, which is very high resolution (but not always 100% reliable, on for example laptops or virtual machines :? ). Usually it serves very well in cases like measuring execution time.
knurf
 
Posts: 4
Joined: December 3rd, 2010, 12:51 pm

Re: Max execution time

Postby Oliver » December 16th, 2010, 4:50 pm

You're correct. I'll get somebody to see if we can whitelist Stopwatch.
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am


Return to C#



cron