Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

DevLiquidKnight

Best way to calculate speed of code?

This topic is 5227 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know you can use a profiler to calculate speed of code but can you also use GetTickCount() to calculate how fast it is? And if so is there anything better to use or is this the best way?

Share this post


Link to post
Share on other sites
Advertisement
"How fast" is relative. You could check the time elapsed between start and end of a function. Profiling, however, gives you a lot of useful information other than just execution time. Things like % of total app time, number of hits, time per call, total time, etc.

Share this post


Link to post
Share on other sites
If you want to test code speed, best to (A) fire through hundreds/thousands of iterations of small code or worst-case scenarios of large code, (B) use GetTickCount() to time intervals longer than several seconds only, because GetTickCount() only updates between 18 and 100 times per second. It is accurate, but the 18 to 100 times per second is the finest resolution it will provide.

Also, if your numbers seem too high and you don''t think you''ll ever live with such abominably slow code... as is often said on these forums, premature optimization is a waste of time. Use that profiler once you''ve got a larger and functional codebase running.

Share this post


Link to post
Share on other sites
QueryPerformanceCounter gives you much better accuracy and precision.

GetTickCount measures in milliseconds, but a millisecond is a looooong time on today''s CPUs ( 1 ms = 1,000,000 cycles on a 1GHz CPU).

Share this post


Link to post
Share on other sites
I haven''t had any problems with DevPartner or the GlowCode profiler.

I can see why you''d want to time manually but it doesn''t seem like its worth the effort expended.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!