Benchmark - FastMapper vs AutoMapper vs Value Injecter Performance Comparison

Test Class
public class Foo
{
	public string Name { get; set; }
	public int Int32 { get; set; }
	public long Int64 { set; get; }
	public int? NullInt { get; set; }
	public float Floatn { get; set; }
	public double Doublen { get; set; }
	public DateTime DateTime { get; set; }
	public Foo Foo1 { get; set; }
	public IEnumerable<Foo> Foos { get; set; }
	public Foo[] FooArr { get; set; }
	public int[] IntArr { get; set; }
	public IEnumerable<int> Ints { get; set; }
}
Data
private static Foo GetFoo()
{
   var o = new Foo
   {
      Name = "foo",
      Int32 = 12,
      Int64 = 123123,
      NullInt = 16,
      DateTime = DateTime.Now,
      Doublen = 2312112,
      Foo1 = new Foo { Name = "foo one" },
      Foos = new List<Foo>
      {
        new Foo {Name = "j1", Int64 = 123, NullInt = 321},
        new Foo {Name = "j2", Int32 = 12345, NullInt = 54321},
        new Foo {Name = "j3", Int32 = 12345, NullInt = 54321},
      },
      FooArr = new[]
      {
        new Foo {Name = "a1"},
        new Foo {Name = "a2"},
        new Foo {Name = "a3"},
      },
      IntArr = new[] { 1, 2, 3, 4, 5 },
      Ints = new[] { 7, 8, 9 },
   };
   
   return o;
}
Mapping
public void MapFromFastMapper(int iterations)
{
    var foo = GetFoo();
    for(int i = 0; i < iterations; i++)
        TypeAdapter.Adapt<Foo, Foo>(foo);
}

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

    var foo = GetFoo();
    for(int i = 0; i < iterations; i++)
        Mapper.Map<Foo, Foo>(foo);
}

public void MapFromValueInjecter(int iterations)
{
    var foo = GetFoo();
    for(int i = 0; i < iterations; i++)
        new Foo().InjectFrom<FastDeepCloneInjection>(foo);
}

Result

Iterations : 1000

FastMapper : 12 miliseconds
ValueInjecter : 270 miliseconds
AutoMapper : 288 miliseconds

Iterations : 10000

FastMapper : 103 miliseconds
ValueInjecter : 2112 miliseconds
AutoMapper : 2115 miliseconds

Iterations : 100000

FastMapper : 968 miliseconds
ValueInjecter : 20880 miliseconds
AutoMapper : 20531 miliseconds

- Benchmark code can be found at here.

Last edited Mar 26, 2014 at 7:44 PM by timucinkivanc, version 3