Questions tagged [stopwatch]

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

837 questions
14
votes
2 answers

How to measure the speed of an Arduino function's execution?

I need to determine the speed with which Arduino executes a certain function. What would be the best time to do that? So far I found something with a Stopwatch class, but I'm wondering if there's any native method to do that.
Eugen
  • 1,537
  • 7
  • 29
  • 57
13
votes
2 answers

Precisely measure execution time of code in thread (C#)

I'm trying to measure the execution time of some bits of code as accurately as possible on a number of threads, taking context switching and thread downtime into account. The application is implemented in C# (VS 2008). Example: public void…
xxbbcc
  • 16,930
  • 5
  • 50
  • 83
13
votes
7 answers

.NET System.Diagnostics.Stopwatch issue (returns values too low)

On my computer the Stopwatch is returning values way too low. For example, 200 ms when I specified Thread.Sleep(1000). The program is supposed to wait 1 second. I also tested with ManualResetEvent.WaitOne(1000) and got the same results. Both…
Ducharme
  • 131
  • 1
  • 3
12
votes
4 answers

Why is my Stopwatch.Frequency so low?

Debug.WriteLine("Timer is high-resolution: {0}", Stopwatch.IsHighResolution); Debug.WriteLine("Timer frequency: {0}", Stopwatch.Frequency); Result: Timer is high-resolution: True Timer frequency: 2597705 This article (from 2005!) mentions…
xofz
  • 5,600
  • 6
  • 45
  • 63
11
votes
7 answers

Profiling .NET applications with Stopwatch

It seems there are no free* .NET performance profilers that can profile on a line-by-line basis. Therefore, I am looking into using Stopwatch for profiling. *free as in freedom, i.e. license includes commercial applications. EDIT: In response to…
Kendall Frey
  • 43,130
  • 20
  • 110
  • 148
11
votes
3 answers

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 timer ticks. I wonder what those are, and why are…
Jader Dias
  • 88,211
  • 155
  • 421
  • 625
11
votes
1 answer

Do I need to stop the stopwatch if the enclosing method is about to return?

Consider the following method: DoTimeIntensiveOperation() { var t = new Stopwatch(); foreach(var element in a_very_long_array) { DoATimeConsumingTask(element); } Console.WriteLine("Took me " + t.Elapsed); …
Superbest
  • 25,318
  • 14
  • 62
  • 134
11
votes
2 answers

What is Free Pascal's equivalent of Delphi's TStopWatch?

I need to implement simple performance benchmarking in Free Pascal. In Delphi I am using TStopWatch record from Diagnostics unit, what can I use in Free Pascal/Lazarus?
kludg
  • 27,213
  • 5
  • 67
  • 118
10
votes
3 answers

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

For example foo() //Some operation bound by an external resource. db,I/O, whatever. vs. var watch = new Stopwatch(); watch.Start(); foo() var time = watch.ElapsedMilliseconds watch.Stop();
Ben McNiel
  • 8,661
  • 10
  • 36
  • 38
10
votes
1 answer

Differences in Elapsed Ticks property of Stopwatch

ElapsedTicks & Elapsed.Ticks are properties of Stopwatch, which I think should be same. And in case they are same, why they should give different outputs ? Code : Stopwatch spwt =…
Pratik
  • 11,534
  • 22
  • 69
  • 99
10
votes
3 answers

Measure method execution time using an attribute (.net core)

I'm interested in measuring the time it takes to execute particular methods. I was thinking it would be really convenient to do this using a Custom Attribute instead of littering methods with code to start/stop stopwatch and sending to logger. If I…
Rob
  • 6,819
  • 17
  • 71
  • 131
10
votes
4 answers

how to calculate execution time of a async method in c#

So I have a Async method which does something asynchronously. private async static void DoSomethingAsync (int i){} I call it in a loop lets say 50 times. for (int i = 0; i < 50; i++) { DoSomethingAsync (i); } At the end of loop I want to…
ahsant
  • 1,003
  • 4
  • 17
  • 25
10
votes
3 answers

What's the difference between creating a new instance with "new() and ".StartNew()"?

Coming from my "answer" to question "Stopwatch in a Task seems to be additive across all tasks, want to measure just task interval" What are the possible differences between creating a new Stopwatch instance as: Stopwatch timer =…
9
votes
3 answers

Stopwatch with breakpoints not adding up correctly

I have a main stopwatch with 4 mini-stopwatches for each step. After a finished time, here is an example of how the timers should look: MAIN: 00 : 14 : 57 ------------------- MINI1: 00 : 04 . 17 MINI2: 00 : 06 . 40 MINI3: 00 : 02 . 54 MINI4: 00 :…
Saad
  • 49,729
  • 21
  • 73
  • 112
9
votes
4 answers

Performance of .Net function calling (C# F#) VS C++

Since F# 2.0 has become a part of VS2010 I take an interest in F#. I wondered what's the point of using it. I'd read a bit and I made a benchmark to measure functions calling. I have used Ackermann's function :) C# sealed class Program { public…
Lukasz Madon
  • 14,664
  • 14
  • 64
  • 108
1 2
3
55 56