Lamloumi Afif
Lamloumi Afif

Reputation: 9081

Testing response time in Asp.net mvc4 application

I have an asp.net mvc4 application , in which i have this class

public class Arbre
{
    public int id_resp = -1;
    Admin notre_admin = new Admin();
    List<Task> _la_liste = new List<Task>();

    public Arbre(int id)
    {
        id_resp = id;
    }

    public List<Task> GetTasksOfExpert(int id_user) {
        List<int> liste =  notre_admin.GetTasksOfExpert(id_user);
        List<Task> liste_finale = new List<Task>();

        for (int i = 0; i < liste.Count; i++) {
            liste_finale.Add(notre_admin.GetTaskListByAffaire(null).Find(x => x.Id_tache == liste[i]));
        }

        return liste_finale;
    }

    public List<Task> GetTasksOfChef(int id_user)
    {
        List<int> liste = notre_admin.GetTasksOfChef(id_user);
        List<Task> liste_finale = new List<Task>();
        for (int i = 0; i < liste.Count; i++)
        {
            liste_finale.Add(notre_admin.GetTaskListByAffaire(null).Find(x => x.Id_tache == liste[i]));
        }
        return liste_finale;
    }

}

I'd like to add a test which helps me to know the approximate time for each method in order to optimize my code.

Upvotes: 1

Views: 209

Answers (2)

Damon
Damon

Reputation: 3012

There are a number of commercial products available that allow you to profile your code (Ants Profiler from RedGate is one that leaps to mind). As Marcom mention MiniProfiler is pretty good (and it's free and quite easy to setup and use).

The other more complex alternative is to investigate AOP and implement functionality around your methods that allow you to log the duration. I've used the AOP functionality from Unity to implement something similar (in combination with Log4Net).

You could use a form of Unit Testing for this, but this is more an integration test than a Unit Test. (e.g. in your integration test you could setup a timer and measure the method execution duration). Integration tests can be slow to run and you wouldn't necessarily be able to get performance metrics from a production system.

Upvotes: 2

Marcom
Marcom

Reputation: 4741

There are a number of ready tools that can help you achieve that. One of my favourites is miniprofiler

I'd give it a go and see if it suits your needs.

Upvotes: 1

Related Questions