6

How to write Performance Test for .Net application? Does nUnit or any other Testing framework provides framework for this?

Edit: I have to measure performance of WCF Service.

3
  • I am looking to test WCF Services for performance> Commented Mar 15, 2010 at 19:41
  • performance in how long it takes typically or under load or ? Commented Mar 15, 2010 at 19:54
  • possible duplicate of .NET benchmarking frameworks Commented Apr 22, 2013 at 20:24

4 Answers 4

12

If you are interested in relative performance of methods and algorithms, you can use the System.Diagnostic.StopWatch class in your NUnit tests to write assertions about how long certain methods take.

In the simple example below, the primes class is instantiated with a [SetUp] method (not shown), as I'm interested in how long the generatePrimes method is taking, not the instantiation of my class, and I'm writing an assertion that this method should take less than 5 seconds. This isn't a very challenging assertion, but hopefully serves as an example of how you could do this.

    [Test]
    public void checkGeneratePrimesUpToTenMillion()
    {
        System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
        timer.Start();
        long[] primeArray = primes.generatePrimes(10000000);
        timer.Stop();
        Assert.AreEqual(664579, primeArray.Length, "Should be 664,579 primes below ten million");
        int elapsedSeconds = timer.Elapsed.Seconds;
        Console.Write("Time in seconds to generate primes up to ten million: " + elapsedSeconds);
        bool ExecutionTimeLessThanFiveSeconds = (elapsedSeconds < 5);
        Assert.IsTrue(ExecutionTimeLessThanFiveSeconds, "Should take less than five seconds");
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Careful, the code above does NOT check the elapsed seconds. timer.Elapsed.Seconds returns the seconds COMPONENT, as in if the timer is 3 minutes and 2 seconds, it will return 2.
2

I came across NTime which looks cool for writing performance Tests.

http://www.codeproject.com/kb/dotnet/NTime.aspx

Comments

0

VS Team System has built in performance testing modules. Worth exploring if u have licence for that.

Comments

0

NUnit provides you with a framework for unit testing: i.e. testing your code in discrete "units" so that you can, amongst other things, be aware when new changes break existing code, or that you have provided a certain level of code coverage. But it does not provide performance testing per se.

For that, you will need another type of tool. If you have a webapp, you might like to take a look at The Grinder or others to be found here:

https://web.archive.org/web/20140101114848/http://www.opensourcetesting.org/performance.php

1 Comment

you can, but typically you'll want the performance measured from outisde the app (as a user would see it), in which case you'll need one of the standalone tools mentioned in the link above or in Vivin's answer.

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.