Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Is there any simple way to calculate time that is spent in each method that's called from the Update and Draw methods? I want to do this to find bottlenecks in my engine. Is that a good way?

share|improve this question
2  
Use a profiling tool. Those are specifically designed for helping you locate performance bottlenecks. –  Jonathan Hobbs Apr 28 '12 at 22:08
add comment

2 Answers 2

up vote 3 down vote accepted

If you want to do it in code as then I suggest you check out System.Diagnostics.Stopwatch class. Its designed for measuring very, very small amounts of time.

I personally use the Visual Studio Profiler. One of my favorite features is it will list all the methods along with the % of processing time they occupy. Very useful for finding bottlenecks.

share|improve this answer
    
thanks I will take a look at this tool –  Vodáček Apr 29 '12 at 4:55
add comment

well Gametime.ElapsedGameTime is how long it takes from frame to frame (however, think its rendering and updating). But, as a comment said, use profiling and good judgement as to whats taking so long. Check any loops because those are generally the reason. Maybe if you could describe any issues you're having, we could help you narrow your search down.

share|improve this answer
    
-1 Unfortunately GameTime won't do the job within a single call. :( The asker is looking for ways to measure time spent within methods which makes GameTime inadequate. –  Jonathan Hobbs Apr 28 '12 at 23:11
    
Yes I know, I said that. However, profiling will get you a lot farther than just timing. –  CobaltHex Apr 28 '12 at 23:41
    
I think the original poster was simply using time as a reference point (considering that time is technically just a human measurement for cycles/lines) which only your second part speaks to by bringing up profiling –  gardian06 Apr 29 '12 at 7:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.