0

I have a C# function that I want to measure execution time:

// save audit log using XML approach
if (records > 0) {

    using(SQLRepository repo = new SQLRepository()) {

        // this is one approach that I want to meassure
        repo.SaveChangeLog(tw.ToString());

        // this is second approach that I want to meassure
        repo.SaveChangeLogApproach2(tw.ToString());
    }
}

Is there something already in Visual Studio that I can use to get those executions times?

Loofer
  • 6,841
  • 9
  • 61
  • 102
VAAA
  • 14,531
  • 28
  • 130
  • 253

2 Answers2

1

You should be using the System.Diagnostics.Stopwatch class.

Justin Niessner
  • 242,243
  • 40
  • 408
  • 536
0

Note that if you time both method calls within the same using statement, the first call may be slower due to instantiation of the repo class.

Loofer
  • 6,841
  • 9
  • 61
  • 102