Benchmark (Complex Model) - FastMapper vs AutoMapper Performance Comparison

Test Classes
public class Address
{
	public int Id { get; set; }
	public string Street { get; set; }
	public string City { get; set; }
	public string Country { get; set; }
}

public class AddressDTO
{
	public int Id { get; set; }
	public string City { get; set; }
	public string Country { get; set; }
}

public class Customer
{
	public int Id { get; set; }
	public string Name { get; set; }
	public decimal? Credit { get; set; }
	public Address Address { get; set; }
	public Address HomeAddress { get; set; }
	public Address[] Addresses { get; set; }
	public ICollection<Address> WorkAddresses { get; set; }
}

public class CustomerDTO
{
	public int Id { get; set; }
	public string Name { get; set; }
	public Address Address { get; set; }
	public AddressDTO HomeAddress { get; set; }
	public AddressDTO[] Addresses { get; set; }
	public List<AddressDTO> WorkAddresses { get; set; }
	public string AddressCity { get; set; }
}
Data
private static Customer GetCustomer()
{
	Customer customer = new Customer()
	{
		Id = 1,
		Name = "Timucin Kivanc",
		Credit = 234.7m,
		Address = new Address() { 
			City = "Istanbul", 
			Country = "Turkey", 
			Id = 1, 
			Street = "Istiklal cad." 
		},
		HomeAddress = new Address() { 
			City = "Istanbul", 
			Country = "Turkey", 
			Id = 2, 
			Street = "Istiklal cad." 
		},
		WorkAddresses = new List<Address>() { 
			new Address() { 
				   City = "Istanbul", 
				   Country = "Turkey", 
				   Id = 5, 
				   Street = "Istiklal cad." 
			},
			new Address() { 
				   City = "Izmir", 
				   Country = "Turkey", 
				   Id = 6, 
				   Street = "Konak" 
			}
		},
		Addresses = new List<Address>() { 
			new Address() { 
				   City = "Istanbul", 
				   Country = "Turkey", 
				   Id = 3, 
				   Street = "Istiklal cad." 
			},
			new Address() { 
				   City = "Izmir", 
				   Country = "Turkey", 
				   Id = 4, 
				   Street = "Konak" 
			}
		}.ToArray()
	};

	return customer;
}
Mapping
public void MapFromFastMapper(int iterations)
{
    var customer = GetCustomer();
    for(int i = 0; i < iterations; i++)
        TypeAdapter.Adapt<Customer, CustomerDTO>(customer);
}

public void MapFromAutoMapper(int iterations)
{
    Mapper.CreateMap<Customer, CustomerDTO>(); 

    var customer = GetCustomer();
    for(int i = 0; i < iterations; i++)
        Mapper.Map<Customer, CustomerDTO>(customer);
}

Result

Iterations : 100

Handwriting Mapper : 2 miliseconds
FastMapper : 0 miliseconds
AutoMapper : 82 miliseconds

Iterations : 1000

Handwriting Mapper : 2 miliseconds
FastMapper : 3 miliseconds
AutoMapper : 106 miliseconds

Iterations : 10000

Handwriting Mapper : 6 miliseconds
FastMapper : 31 miliseconds
AutoMapper : 1088 miliseconds

Iterations : 100000

Handwriting Mapper : 62 miliseconds
FastMapper : 289 miliseconds
AutoMapper : 10620 miliseconds

Iterations : 1000000

Handwriting Mapper : 608 miliseconds
FastMapper : 2976 miliseconds
AutoMapper : 106336 miliseconds

- Benchmark code can be found at here.

Last edited Mar 26, 2014 at 8:40 PM by timucinkivanc, version 1