How to test Entity Framework performance?

Asked

Viewed 109 times

3

I want to create mapping with heritage Person -> Customers, etc

But I would like to test performance with the 3 types of mapping( TPH,TPT,TPC)

How do I do it? Someone has had the experience to say which of the 3 becomes easier and faster ?

3 answers

1

You can use the good old stop

public void Teste()
{
    Stopwatch sw = Stopwatch.StartNew();
    var pessoas = MeuContexto.Pessoas.ToList();
    sw.Stop();
    Console.WriteLine("Tempo demorado = {0}ms", sw.Elapsed);
}

0

TPH (Table per Hierarchy)

All entities in the hierarchy will be mapped to a single table. So, no need to do joins to recover the data, generally having a better performance compared to TPT.

The drawback is data redundancy. Some columns related to specific entity classes may contain null values.

TPT (Table per Type)

Each entity in the class hierarchy is mapped to a different table. So there is need to do Join when selecting the data, generally having a lower performance than TPH.

Implement if necessary for the sake of standardization and design (avoids redundancy). With respect to performance is lower than TPH.

TPC (Table per Concrete class)

Each concrete class (which can be instantiated in the class hierarchy) is mapped to a specific table, contemplating the abstract class fields.

As you can see, it’s not just a matter of performance, but the decision for one or the other Pattern will also depend on your modeling.

To test, I recommend building your class hierarchy and using a Stopwatch when accessing data like @Luís Deschamps Rudge suggested in his reply and using the Entity Framework Profile to see what is happening "behind the scenes" in the database and so make the decision as your need.

-1

Use Analyze from Visual Studio, with it you will be able to know where it is taking the most time in your application, we have already solved some performance problems using it.

You go to Analyze in the Menu:

inserir a descrição da imagem aqui

then your application will go into debug to start collecting the information, then at this instant run the tests you want, while it collects.

inserir a descrição da imagem aqui

When you finish you will go into Stop Profile.

inserir a descrição da imagem aqui

Wait, your application will exit the debug and the result will be generated, then just analyze.

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.