1

I want to record the amount of time it takes to execute my custom method, but I have never worked with the timer class or methods before, I know I'm doing something wrong, .

Here's what I have.

System.Timers.Timer Time;
int Mili = 0 ;

data = Generate();

Time.Enabled = true;
BSort= BubbleSort(data);

Time.Enabled = false;
Rob
  • 26,989
  • 16
  • 82
  • 98
userID
  • 19
  • 1
  • 3
  • Please format your code properly. – Rob Jan 08 '17 at 04:33
  • 1
    Possible duplicate of [Calculate the execution time of a method](http://stackoverflow.com/questions/14019510/calculate-the-execution-time-of-a-method) – Mohsen Esmailpour Jan 08 '17 at 04:40
  • Or a possible duplicate of [How do I measure how long a function is running?](https://stackoverflow.com/questions/10107140/how-do-i-measure-how-long-a-function-is-running) – h.m.i.13 Aug 01 '22 at 14:31

1 Answers1

10

A timer is for a periodic event. You should look at the Stopwatch class.

var sw = Stopwatch.StartNew();

// your code ...

// sw.Stop(), sw.Elapsed, etc.
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445