Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write Performance Test for .Net application?

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.

like image 635
Amitabh Avatar asked Mar 15 '10 19:03

Amitabh


2 Answers

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");
    }
like image 94
Paddyslacker Avatar answered Oct 23 '22 17:10

Paddyslacker


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

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

like image 28
Amitabh Avatar answered Oct 23 '22 18:10

Amitabh