Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An efficient way to record time taken to execute a method in C#

I'm looking for a simple, reusable way to record the time taken to execute a method in my .NET (MVC) project and record it it using NLog and wondered if anybody had any suggestions on how to implement this?

To maintain clean code and readability, I don't really want to have to integrate it into my code if possible.

If anybody has any suggestions, I'd love to hear them.

like image 259
Nick Avatar asked Nov 30 '11 09:11

Nick


1 Answers

Use Stopwatch class

Stopwatch time = Stopwatch.StartNew();
time.Stop();
var milliseconds= time.ElapsedMilliseconds;
like image 152
Stecya Avatar answered Sep 30 '22 20:09

Stecya