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,653
  • 9
  • 58
  • 99
VAAA
  • 13,535
  • 24
  • 118
  • 230

2 Answers2

1

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

Justin Niessner
  • 236,029
  • 38
  • 403
  • 530
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,653
  • 9
  • 58
  • 99