2

I am using asp.net mvc 2.0 and I want to test how long it takes to execute some of my code.

In one scenario I do this

  1. load xml file up.
  2. validate xml file and deserailze.
  3. validate all rows in the xml file with more advanced validation that cannot be done in the schema validation.
  4. then I do a bulk insert.

I want to measure how long steps 1 to 3 take and how long step 4 takes.

I tried to do like DateTime.UtcNow in areas and subtract them but it told me it took like 3 seconds but I know that is not right as steps 1 to 4 take 2mins to do.

2 Answers 2

3

You can use the Stopwatch class.

Stopwatch s = new Stopwatch();
s.Start();
// Run code to be timed
s.Stop();
Debug.Print(s.Elapsed.ToString());
s.Reset();
Sign up to request clarification or add additional context in comments.

Comments

1

You could use Log4Net and save out when you enter the method and when you exit the method. Plus you could also log at certain points within the method.

Log4Net will give each entry a time code and you can see exactly how long everything is taking.

1 Comment

I am just looking for something very simple(like the stopwatch). In the future I think I will check this out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.