Questions tagged [stopwatch]

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

837 questions
6
votes
2 answers

Stopwatch in JavaScript

Before marking the question duplicate, I want to tell that I have been through all the stopwatch and JavaScript searches but as I am new to the JavaScript, so I can not come to the possible solution myself and I need the help from you guys. What I…
Imam Bux
  • 1,006
  • 11
  • 27
6
votes
3 answers

Best way to implement a high resolution DateTime.UtcNow in C#?

I am trying to implement a time service that will report time with greater accuracy than 1ms. I thought an easy solution would be to take an initial measurement and use StopWatch to add a delta to it. The problem is that this method seems to…
Chuu
  • 4,301
  • 2
  • 28
  • 54
6
votes
5 answers

Start a stopwatch from specified time

Im trying to start a stopwatch from a given time (decimal value pulled from a database). However, because the Stopwatch.Elapsed.Add returns a new Timespan rather than modify the Stopwatch, I can't work out the best way forward. var offsetTimeStamp =…
dynamicuser
  • 1,522
  • 3
  • 24
  • 52
6
votes
2 answers

Stopwatch in a Task seems to be additive across all tasks, want to measure just task interval

I'm running in a loop and kicking off tasks in the following manner: var iResult = new List(); foreach(var i in myCollection) { var task = Task.Factory.StartNew(() => DoSomething(), TaskCreationOptions.LongRunning); …
Prescott
  • 7,312
  • 5
  • 49
  • 70
6
votes
4 answers

PowerShell timer/stopwatch accuracy

I find that the System.Diagnostics.Stopwatch class has what seems to be measurable inaccuracy, even over a short time period (i.e. 20 seconds). My process is showing an elapsed time of 20.3+ seconds for a process coded to run 20 seconds: $elapsed =…
Local Needs
  • 537
  • 3
  • 5
  • 20
6
votes
5 answers

Set start time for Stopwatch program in C#

I want to write a simple stopwatch program, I can make it work with the following code public Form1() { InitializeComponent(); } System.Diagnostics.Stopwatch ss = new System.Diagnostics.Stopwatch { }; private void…
Kyle Dam
  • 63
  • 1
  • 1
  • 3
6
votes
1 answer

Pass a Function with multiple parameters as a Parameter

I have this piece of code, that takes a single function with no parameter, and return's its runtime. public static Stopwatch With_StopWatch(Action action) { var stopwatch = Stopwatch.StartNew(); action(); stopwatch.Stop(); return…
Dominik Antal
  • 3,281
  • 4
  • 34
  • 50
6
votes
3 answers

Alternative to stopwatch?

I am working on a very simple stopwatch using WPF but using the System.Diagnostics stopwatch was very slow and not reliable at all, compared to my system clock every 1 second from my application was 3 seconds on an actual clock. I did some search…
Guapo
  • 3,446
  • 9
  • 36
  • 63
5
votes
3 answers

Why is does my stopwatch keep reseting after 1 second

So I have the following code block: var sw = new Stopwatch(); sw.Start(); while (sw.Elapsed.Seconds<10) { System.Threading.Thread.Sleep(50); Console.WriteLine(sw.Elapsed.Milliseconds.ToString() + " ms"); } sw.Stop(); and in the output I…
scott
  • 2,991
  • 5
  • 36
  • 47
5
votes
2 answers

Stopwatch class that shows min, max, average, ... times?

I am looking for a java class that simulates a StopWatch (like Spring's StopWatch or Commons' StopWatch) but that would give minimum, maximum and average times. Preferable also average over last n runs as well. Is there such a thing or do I just…
Wim Deblauwe
  • 25,113
  • 20
  • 133
  • 211
5
votes
1 answer

Using `TStopWatch` without `free`

I am using TStopWatch for high-precision timekeeping in Delphi 10.2 Tokyo. This website: https://www.thoughtco.com/accurately-measure-elapsed-time-1058453 has given the following example: var sw : TStopWatch; elapsedMilliseconds :…
blackcanopus
  • 153
  • 1
  • 4
5
votes
2 answers

Spring StopWatch concurrency

I have a Bean configured as follow: @Bean(name = "myStopWatch") @Scope(value = "prototype") public MyStopWatch myStopWatch() { return new MyStopWatch(); } And MyStopWatch class is as follow: import…
hublo
  • 1,010
  • 2
  • 12
  • 33
5
votes
1 answer

Javascript Countdown Timer

I need a count down timer that can display second:miliseconds format, I found one that I figured I could modify it to show this like 4:92 but it doesn't want to work for me for some reason. It works fine on the site, but I try and put it into my…
Sean
  • 8,401
  • 15
  • 40
  • 48
5
votes
4 answers

Is there are any implementations of stopwatch in TypeScript?

I would like to run performance measurement for some critical functions on the website written on TypeScript. I'm wondering if there is any implementation of stopwatch similar to .NET System.Diagnostics.Stopwatch class in TypeScript?
Aliaksei Maniuk
  • 1,534
  • 2
  • 18
  • 30
5
votes
2 answers

Simple lockless stopwatch

According to MSDN, the Stopwatch class instance methods aren't safe for multithreaded access. This can also be confirmed by inspecting individual methods. However, since I only need simple "time elapsed" timers at several places in my code, I was…
Lou
  • 4,244
  • 3
  • 33
  • 72