简体   繁体   中英

C# how to measure elapsed time?

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;

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM