.NET में किसी विधि के निष्पादन के समय को मापने के लिए स्टॉपवॉच वर्ग का उपयोग करें -
Stopwatch s = Stopwatch.StartNew();
अब एक फ़ंक्शन सेट करें और मिलीसेकंड में निष्पादन समय प्राप्त करने के लिए ElapsedMilliseconds गुण का उपयोग करें -
s.ElapsedMilliseconds
आइए देखें पूरा कोड -
उदाहरण
using System;
using System.IO;
using System.Diagnostics;
public class Demo {
public static void Main(string[] args) {
Stopwatch s = Stopwatch.StartNew();
display();
for (int index = 0; index < 5; index++) {
Console.WriteLine("Time taken: " + s.ElapsedMilliseconds + "ms");
}
s.Stop();
}
public static void display() {
Console.WriteLine("Demo function!");
}
} आउटपुट
Demo function! Time taken: 15ms Time taken: 16ms Time taken: 16ms Time taken: 16ms Time taken: 16ms