The System.Diagnostics.Stopwatch class in .Net, used to accurately measure elapsed time.
Questions tagged [stopwatch]
837 questions
9
votes
1 answer
Stopwatch to time an async/await method inaccurate
I'm writing some performance tests, and want to be able to time a method that is asynchronous. The code looks like this, where action is a Func>:
var sw = new Stopwatch();
HttpResponseMessage response =…

GoatInTheMachine
- 3,583
- 3
- 25
- 35
9
votes
3 answers
Is Stopwatch really broken?
At MSDN page for Stopwatch class I discovered link to interesting article which makes following statement about Stopwatch:
However there are some serious issues:
This can be unreliable on a PC with multiple processors. Due to a bug in
the BIOS,…

Jakub Šturc
- 35,201
- 25
- 90
- 110
8
votes
3 answers
Capturing the executing time between 2 statements Java?
I want to capture the time take to go from statement A to Statement B in a Java class. In between these statements there are many web service calls made. I wanted to know if there is some stop watch like functionality in java that i could use to…

Kaddy
- 1,226
- 7
- 21
- 34
8
votes
2 answers
How do i get from Stopwatch.GetTimestamp() to a DateTime?
Duplicate of: How to get timestamp of tick precision in .NET / C#?
How do i get from Stopwatch.GetTimestamp() to a DateTime
Assume Stopwatch.IsHighResolution is true

Simon
- 33,714
- 21
- 133
- 202
8
votes
3 answers
Helper class for performance tests using StopWatch class
In this example code i am using a simple StopWatch to test time that it takes to complete a given task/action
StopWatch SW1 = new StopWatch();
SW1.Start();
SomeAction();
SW1.Stop();
sting results =…

LoneXcoder
- 2,121
- 6
- 38
- 76
7
votes
3 answers
C# Trying to wrap a function with a stopwatch
I've been attempting to see how long functions take to execute in my code as practice to see where I can optimize. Right now I use a helper class that is essentially a stopwatch with a message to check these. The goal of this is that I should be…

Blankdud
- 698
- 5
- 9
- 22
7
votes
3 answers
Unrecognized selector sent to instance NSTimer Swift
I'm trying to developing an app that includes a simple Stopwatch feature. I'm using Xcode 6 and the Swift language. Here is the code in FirstViewController
@IBAction func Stopwatch (Sender:UIButton) {
var startTime = NSTimeInterval()
func…

That_one_guy
- 71
- 1
- 2
7
votes
6 answers
Javascript timer just for minutes and seconds
I found a JSFiddle with a timer that counts up every second.
Except i want this to work with just the minutes and seconds. No hours.
Any ideas?

mike
- 71
- 1
- 1
- 2
6
votes
2 answers
JavaFX stopwatch timer
This is a class for a simple stopwatch for JavaFX, style the Label object as desired
package aaa;
import java.text.SimpleDateFormat;
import java.util.Date;
import javafx.beans.property.SimpleStringProperty;
/**
*
* @author D07114915
*/
public…

KEV
- 209
- 1
- 2
- 9
6
votes
4 answers
Visual C++ Stopwatch
I wonder what is the best way to measure the execution time of some code in C++. Is there any built in Stopwatch (.Net) alike class? I am developing C++ on VS2010. How (if) can i use the .Net libraries inside my C++ project?? Thank you In advance.

tropicana
- 1,403
- 2
- 19
- 27
6
votes
4 answers
Does Stopwatch.Gettimestamp ever roll over? Or roll back?
In using Stopwatch.GetTimestamp() we find that if you record the return value and then continue calling it and comparing to the previous return value, it will eventually but unpredictably return a value less than the original.
Is this expected…

Wayne
- 2,959
- 3
- 30
- 48
6
votes
1 answer
Datetime Granularity between 32bit and 64bit Windows
I have create a little engineering app for some network debugging. It takes a list of IP addresses and pings them, with user set timeout and rate. It logs the average round-trip time and every time one of the sends fails it logs it's duration of…

tigerswithguitars
- 2,497
- 1
- 31
- 53
6
votes
3 answers
C# TimeSpan.FromTicks() inaccurate?
I have been using C# for some time now to make a small game, and while testing said game on a different PC I came across some strange elapsed time issues.
I have everything set up in this game to be updated based on time passed since the last game…

Tony
- 75
- 1
- 5
6
votes
1 answer
.Net StopWatch and Powershell
I have a powershell script that is currently running every 4 hours via task scheduler. It cleans a drive and when it's done it fires off an email to me telling me what it moved and where and the amount of time it took to perform this task.
However,…

Ochuse
- 219
- 1
- 5
- 12
6
votes
2 answers
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 integrate into realtime sports timing math…

mothy
- 147
- 2
- 8