If you haven’t read my previous article on AutoMapper, please read it first.

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:

            var autoMapperCVI = new List<CustomerViewItem>();
            foreach (var customer in customers)
            Console.WriteLine(string.Format(“AutoMapper: {0}”, stopwatch.ElapsedMilliseconds));

Measurement of the manual mapping time:

            var manualCVI = new List<CustomerViewItem>();
            foreach (var customer in customers)
                var customerViewItem = new CustomerViewItem()
                                               FirstName = customer.FirstName,
                                               LastName = customer.LastName,
                                               FullName = customer.LastName + ” “ + customer.FirstName,
                                               DateOfBirth = customer.DateOfBirth.ToLongDateString(),
                                               CompanyName = customer.Company.Name,
                                               NumberOfOrders = customer.NumberOfOrders,
                                               VIP = customer.VIP ? “Y” : “N”
            Console.WriteLine(string.Format(“Manual Mapping: {0}”, stopwatch.ElapsedMilliseconds));

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.

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someone