Skip to content

Performance figures

Jon P Smith edited this page Dec 24, 2018 · 6 revisions

In the GitHub repo is a project/assembly called Benchmarking which uses the excellent BenchmarkDotNet library to check handcoded version against the same feature run by GenericServices. This page contains the timings taken in April 2018 (first release) for EfCore.GenericServices 2.0.0, which uses .NET Core 2.1 and EF Core 2.1.4. EF Core 2.1 is a bit faster than 2.0 so the figures change a bit.

I used the fastest database I could find, which turned out to be SQLite in-memory database, so that the database part was minimised.

The first example is for the simplest possible update – in this case I update the publication date of a book. I opened up the Book's PublishedOn property, and I update it via AutoMapper as well as via a DDD-styled update method. Here are the results

Method Mean (us) Error (us) StdDev (us)
HandCoded, PropetyUpdate 469.1 8.600 7.623
GenericService, AutoMapper 493.7 3.060 2.713
5%+-2%
HandCoded, MethodCall 465.0 4.354 3.860
GenericServices, MethodCall 496.8 8.258 7.321
7%+-2%

This is about the fastest database update I could find, and the difference between hand-coded and GenericServices' versions were only 20 to 25 us (us = 1/1,000,000 second), which equates to ~6% slower. Note also that calling a method is just as fast as setting the property (GenericServices builds and caches LINQ expressions to call the methods, which are very fast).

The second example is a more complex update, where it adds a new Review entity to the Book. This takes a little longer inside EF Core and the database provider.

Method Mean (us) Error (us) StdDev (us)
HandCoded, MethodCall 589.0 6.977 6.526
GenericServices, MethodCall 624.3 11.898 11.129
6%+-2%

This shows that the difference is still about 35 us, but because the database accesses take longer it now only equates to a 6% difference, with a +- of 2%.

Finally, I do a complex Projection of 100 Books to provide the display of the user. This is using AutoMapper via GenericServices (the hand-coded version is a LINQ Select method with hand-coded mappings).

Method Mean (ms) Error (ms) StdDev (ms)
HandCoded 2.817 0.0255 0.0199
GenericServices 2.839 0.0435 0.0364
1%+-3%

GenericServices and HandCoded come out about the same, within the error range.