Solved

Responsiveness of My.Computer.Clock.TickCount, and ways to test speed

Posted on 2006-10-22
3
176 Views
Last Modified: 2010-04-23

Hey, I'm trying to speed tweak my code, and I've put a bunch of Debug.Print(My.Computer.Clock.TickCount)'s (to get a sense for which parts are slowest) in a particularly time consuminng procedure and here's a weird thing -- it seems like the My.Computer.Clock.TickCount calls themselves are slowing down the procedure -- anyone else seen that?

Aside from that, anybody have a better or slick way of trying to zero in on the time consuming parts of your code?
0
Comment
Question by:riceman0
  • 2
3 Comments
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 250 total points
ID: 17786863
The main problem of TickCount is low precision - about 20 ms. Of course, Debug.Print + time counting change execution time, but there is nothing to do with this.
For high precision time counting use StopWatch class.
0
 
LVL 34

Accepted Solution

by:
Sancler earned 250 total points
ID: 17792618
Although I agree with AlexFM about the lack of precision using Ticks, my attitude is that any case in which that degree of precision matters is not likely to be the real problem.  Users are unlikely to be bothered by nanosecond differences.

In investigating which is the slowest part of any code what matters is the relative result, not the absolute.  Yes, the actual process of timing different elements of code may affect how long that code takes to execute but, so far as I know, it does so to the same extent whatever the underlying code is.  

So I start with Tick prints at a number of points.  If those highlight major (particularly unexpected) differences in particular areas, I refine them within those areas.  If I get down to a level at which that approach does not produce meaningful results in terms of precision I then program specific test routines, looping the code in those areas a sufficient number of times to make the relative results meaningful.

But my watchword is always "does it matter?".  Nanosecond differences do matter if they are repeated enough times.  Hence the looping tests if it gets down to that level.  Otherwise ...

Roger
0
 
LVL 34

Expert Comment

by:Sancler
ID: 17878215
After sales service ;-)

>>
Yes, the actual process of timing different elements of code may affect how long that code takes to execute but, so far as I know, it does so to the same extent whatever the underlying code is.
<<

Or perhaps not, at least with StopWatch.  See here

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_22047746.html

Roger
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now