Questions tagged [stopwatch]

The System.Diagnostics.Stopwatch class in .Net, used to accurately measure elapsed time.

390
votes
5answers
363k views

Calculate the execution time of a method

Possible Duplicate: How do I measure how long a function is running?I have an I/O time-taking method which copies data from a location to another. What's the best and most real way of calculating ...
88
votes
3answers
55k views

Stopwatch vs. using System.DateTime.Now for timing events [duplicate]

I wanted to track the performance of my code so I stored the start and end time using System.DateTime.Now. I took the difference between the two as the time my code to execute. I noticed though that ...
15
votes
3answers
11k views

Raise event in high resolution interval/timer

I want to use the highest possible resolution timer using c#. For example, I want to raise an event every 11 ticks (I've heard that tick is the highest possible counter in pc). I tried timer and found ...
16
votes
6answers
13k views

How accurate is Thread.Sleep(TimeSpan)?

I've come across a unit test that is failing intermittently because the time elapsed isn't what I expect it to be.An example of what this test looks like is:Stopwatch stopwatch=new Stopwatch();...
80
votes
15answers
157k views

Is there a stopwatch in Java?

Is there a stopwatch in Java? On google I only find code of stopwatches which don't work - they always return 0 milliseconds.This code that I found doesn't work but I don't see why.public class ...
26
votes
8answers
24k views

How accurate is System.Diagnostics.Stopwatch?

How accurate is System.Diagnostics.Stopwatch? I am trying to do some metrics for different code paths and I need it to be exact. Should I be using stopwatch or is there another solution that is more ...
35
votes
10answers
29k views

How do I measure how long a function is running?

I want to see how long a function is running. So I added a timer object on my form, and I came out with this code:private int counter=0;// Inside button click I have:timer=new Timer();timer....
18
votes
4answers
4k views

System.Diagnostics.Stopwatch returns negative numbers in Elapsed… properties

Is it normal behaviour that Stopwatch can return negative values? Code sample below can be used to reproduce it.while (true){Stopwatch sw=new Stopwatch();sw....
17
votes
3answers
8k views

Can the .NET Stopwatch class be THIS terrible?

I'm making an application that needs some pretty tight timing, and the Stopwatch class is the perfect solution. However, I noticed sometimes, when running on a small panel PC, the Stopwatch values ...
69
votes
7answers
14k views

Can Stopwatch be used in production code?

I need an accurate timer, and DateTime.Now seems not accurate enough. From the descriptions I read, System.Diagnostics.Stopwatch seems to be exactly what I want. But I have a phobia. I'm nervous ...
33
votes
4answers
20k views

Difference between ElapsedTicks, ElapsedMilliseconds, Elapsed.Milliseconds and Elapsed.TotalMilliseconds? (C#)

I'm totally confused between these 4. What is the difference between ElapsedMilliseconds (long), ElapsedTicks (long), Elapsed.TotalMilliseconds (double) and Elapsed.Milliseconds (int)? I have a ...
11
votes
3answers
6k views

What are timer ticks, the unit used by Stopwatch.ElapsedTicks

I used to think that Stopwatch.ElapsedTicks was equal to Stopwatch.Elapsed.Ticks.But it isn't. While the latter is a number of 100 nanoseconds periods, the former use a mysterious unit called ...
5
votes
2answers
1k views

Format realtime stopwatch timer to the hundredth using Swift

I have an app using an NSTimer at centisecond (0.01 second) update intervals to display a running stopwatch in String Format as 00:00.00 (mm:ss.SS). (Basically cloning the iOS built-in stopwatch to ...
10
votes
3answers
3k views

What, if any, is the resource penalty for using System.Diagnostics.Stopwatch?

For examplefoo() //Some operation bound by an external resource. db,I/O, whatever.vs.var watch=new Stopwatch();watch.Start();foo()var time=watch.ElapsedMillisecondswatch.Stop();
13
votes
2answers
2k views

Multicore and thread aware .Net stopwatch?

As we all know the stopwatch might have issues in a multi-threaded async application that will be running on all cores.On a multiprocessor computer, it does not matter which processor the thread ...

153050per page
angop.ao, elkhabar.com, noa.al, afghanpaper.com, bbc.com, time.com, cdc.gov, nih.gov, xnxx.com, github.com,