-
Notifications
You must be signed in to change notification settings - Fork 96
Performance figures
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).
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 | 530.9 | 4.003 | 3.343 |
GenericService, AutoMapper | 551.4 | 5.624 | 5.261 |
4% | |||
HandCoded, MethodCall | 529.1 | 5.583 | 5.223 |
GenericServices, MethodCall | 555.7 | 5.828 | 5.451 |
5% |
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/1000,000 second), which equates to 5% 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 | 773.8 | 8.882 | 7.874 |
GenericServices, MethodCall | 800.7 | 11.262 | 7.874 |
3% |
This shows that the difference is still about 25 us, but because the database accesses take longer it now only equates to a 3% difference.
Finally, I do a complex Projection of 100 Book's 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 | 11.35 | 0.2433 | 0.4970 |
GenericServices | 11.23 | 0.0838 | 0.0784 |
-1% |
This is a bit misleading, as the GenericServices isn't faster than the hand-coded – sometimes it comes out faster and sometimes slower. Basically, the performance cost of GenericServices is smaller than the error margin so you can't really measure it.