February 28, 2010 .NET, AutoMapper, Frameworks
February 28, 2010 .NET, AutoMapper, Frameworks
After I’ve posted this article one guy was really concerned about the performance of AutoMapper.
So, I have decided to measure execution time of the AutoMapper mapping and manual mapping code.
First of all I have code which returns me 100000 almost random Customers which goes to the customers list.
Measurement of AutoMapper mapping time:
Measurement of the manual mapping time:
I ran my tests many times and one of the possible outputs could be:
AutoMapper: 2117
Manual Mapping: 293
It looks like manual mapping is 7 times faster than automatical. But hey, it took 2 sec to map handrend thouthands of customers.
It is one of the situations where you should decide if the performance is so critical for you or no. I don’t think that there are a lot of cases when you really need to choice manual mapping exactly because of performance issue.
Markdown | Result |
---|---|
*text* | text |
**text** | text |
***text*** | text |
`code` | code |
~~~ more code ~~~~ |
more code |
[Link](https://www.example.com) | Link |
* Listitem |
|
> Quote | Quote |
Yes, useful information.
This features is always compromise between speed and performance.
I had similar situation when tried to use compile dfunction, using CodeDom. I noticed that method which invokes function from given assembly was wery slow. Then I threw exception inside my function and understood what really happens. There was stak trace with 5 function calls. Reflection can't do it in other way, beacause it don't have any information about objects, which are reflected.
In my case I compiled predefined delegate for my function and put it into separate library. After compilation I wrote method, which obtains that delegate from function with given signature.
Performance was increased more then 1000 times.
Well done, man.
Reflections is really nice and powerful thing.
Many of new features and frameworks are build on it. And we also going to play with it we need to be careful.
Thanks for sharing experience.
Andriy, have you tried this using Mapper.Map, List>(customers)?
I'd love to see if it performs comparable to manual case.
Hi, I haven't tried this. But as far as I know mapping whole collection at once is by far more sufficient.