private static long BenchOoMapper(int mappingsCount) { var s = new BenchSource(); var d = new BenchDestination(); return(Benchmark(mappingsCount, () => d = Mapper.Map(s, d))); }
static long BenchHandwrittenMapper(int mappingsCount) { var s = new BenchSource(); var d = new BenchDestination(); var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < mappingsCount; ++i) { d = Map(s, d); } sw.Stop(); return(sw.ElapsedMilliseconds); }
static long BenchBLToolkit2(int mappingsCount) { var s = new BenchSource(); var d = new BenchDestination(); var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < mappingsCount; ++i) { BLToolkit.Mapping.Map.ObjectToObject<BenchDestination>(s); d = BLToolkit.Mapping.Map.ObjectToObject<BenchDestination>(s); } sw.Stop(); return sw.ElapsedMilliseconds; }
private static BenchDestination.Int1 Map(BenchSource.Int1 s, BenchDestination.Int1 d) { if (s == null) { return null; } if (d == null) { d = new BenchDestination.Int1(); } d.i = s.i; d.str1 = s.str1; d.str2 = s.str2; return d; }
static long BenchBLToolkit2(int mappingsCount) { var s = new BenchSource(); var d = new BenchDestination(); var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < mappingsCount; ++i) { BLToolkit.Mapping.Map.ObjectToObject <BenchDestination>(s); d = BLToolkit.Mapping.Map.ObjectToObject <BenchDestination>(s); } sw.Stop(); return(sw.ElapsedMilliseconds); }
static long BenchEmitMapper(int mappingsCount) { var mapper = ObjectMapperManager.DefaultInstance.GetMapper <BenchSource, BenchDestination>(); var s = new BenchSource(); var d = new BenchDestination(); var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < mappingsCount; ++i) { mapper.Map(s, d); } sw.Stop(); return(sw.ElapsedMilliseconds); }
static long BenchAutoMapper(int mappingsCount) { AutoMapper.Mapper.CreateMap<BenchSource.Int1, BenchDestination.Int1>(); AutoMapper.Mapper.CreateMap<BenchSource.Int2, BenchDestination.Int2>(); AutoMapper.Mapper.CreateMap<BenchSource, BenchDestination>(); var s = new BenchSource(); var d = new BenchDestination(); var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < mappingsCount; ++i) { AutoMapper.Mapper.Map(s, d); } sw.Stop(); return sw.ElapsedMilliseconds; }
static long BenchAutoMapper(int mappingsCount) { AutoMapper.Mapper.CreateMap <BenchSource.Int1, BenchDestination.Int1>(); AutoMapper.Mapper.CreateMap <BenchSource.Int2, BenchDestination.Int2>(); AutoMapper.Mapper.CreateMap <BenchSource, BenchDestination>(); var s = new BenchSource(); var d = new BenchDestination(); var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < mappingsCount; ++i) { AutoMapper.Mapper.Map(s, d); } sw.Stop(); return(sw.ElapsedMilliseconds); }
private static BenchDestination.Int2 Map(BenchSource.Int2 s, BenchDestination.Int2 d) { if (s == null) { return null; } if (d == null) { d = new BenchDestination.Int2(); } d.i1 = Map(s.i1, d.i1); d.i2 = Map(s.i2, d.i2); d.i3 = Map(s.i3, d.i3); d.i4 = Map(s.i4, d.i4); d.i5 = Map(s.i5, d.i5); d.i6 = Map(s.i6, d.i6); d.i7 = Map(s.i7, d.i7); return d; }
public void Setup() { var fixture = new Fixture(); _benchSourceEmitMapper = ObjectMapperManager.DefaultInstance.GetMapper <BenchSource, BenchDestination>(); _simpleEmitMapper = ObjectMapperManager.DefaultInstance.GetMapper <B2, A2>(); var config = new MapperConfiguration(cfg => { cfg.CreateMap <BenchSource, BenchDestination>(); cfg.CreateMap <BenchSource.Int1, BenchDestination.Int1>(); cfg.CreateMap <BenchSource.Int2, BenchDestination.Int2>(); cfg.CreateMap <A2, B2>(); }); _autoMapper = config.CreateMapper(); _benchSource = fixture.Create <BenchSource>(); _simpleSource = fixture.Create <B2>(); _simple100List = fixture.CreateMany <B2>(100).ToList(); _simple1000List = fixture.CreateMany <B2>(1000).ToList(); }
static BenchDestination Map(BenchSource s, BenchDestination d) { if (s == null) { return(null); } if (d == null) { d = new BenchDestination(); } d.i1 = Map(s.i1, d.i1); d.i2 = Map(s.i2, d.i2); d.i3 = Map(s.i3, d.i3); d.i4 = Map(s.i4, d.i4); d.i5 = Map(s.i5, d.i5); d.i6 = Map(s.i6, d.i6); d.i7 = Map(s.i7, d.i7); d.i8 = Map(s.i8, d.i8); d.n2 = s.n2; d.n3 = s.n3; d.n4 = s.n4; d.n5 = s.n5; d.n6 = s.n6; d.n7 = s.n7; d.n8 = s.n8; d.n9 = s.n9; d.s1 = s.s1; d.s2 = s.s2; d.s3 = s.s3; d.s4 = s.s4; d.s5 = s.s5; d.s6 = s.s6; d.s7 = s.s7; return(d); }
private static BenchDestination Map(BenchSource s, BenchDestination d) { if (s == null) { return null; } if (d == null) { d = new BenchDestination(); } d.i1 = Map(s.i1, d.i1); d.i2 = Map(s.i2, d.i2); d.i3 = Map(s.i3, d.i3); d.i4 = Map(s.i4, d.i4); d.i5 = Map(s.i5, d.i5); d.i6 = Map(s.i6, d.i6); d.i7 = Map(s.i7, d.i7); d.i8 = Map(s.i8, d.i8); d.n2 = s.n2; d.n3 = s.n3; d.n4 = s.n4; d.n5 = s.n5; d.n6 = s.n6; d.n7 = s.n7; d.n8 = s.n8; d.n9 = s.n9; d.s1 = s.s1; d.s2 = s.s2; d.s3 = s.s3; d.s4 = s.s4; d.s5 = s.s5; d.s6 = s.s6; d.s7 = s.s7; return d; }
public override void Execute() { var formatProvider = CultureInfo.CurrentCulture; var maxIterations = this.MaxIterations; var stringIntArray = new string[maxIterations]; var stringDecimalArray = new string[maxIterations]; var stringGuidArray = new string[maxIterations]; var stringDateTimeArray = new string[maxIterations]; var guidArray = new Guid[maxIterations]; var intArray = new int[maxIterations]; var decimalArray = new decimal[maxIterations]; var doubleArray = new double[maxIterations]; var dateTimeArray = new DateTime[maxIterations]; var customerArray = new Customer[maxIterations]; var customerDtoArray = new CustomerDto[maxIterations]; var personArray = new Person[maxIterations]; var personStringArray = new PersonStringDto[maxIterations]; var addressArray = new Address[maxIterations]; var benchSourceArray = new BenchSource[maxIterations]; var displayResourceEnumArray = new DisplayAttributeResourceEnum[maxIterations]; var displayResxEnumArray = new DisplayAttributeResxEnum[maxIterations]; var displayEnumArray = new DisplayAttributeEnum[maxIterations]; var descriptionEnumArray = new DescriptionAttributeEnum[maxIterations]; var int32EnumArray = new Int32Enum[maxIterations]; var benchSource = new BenchSource(); for (int i = 0; i < maxIterations; i++) { stringIntArray[i] = i.ToString(formatProvider); stringDecimalArray[i] = (i * 0.9m).ToString(formatProvider); stringGuidArray[i] = Guid.NewGuid().ToString(); intArray[i] = i; decimalArray[i] = i * 0.9m; doubleArray[i] = i * 0.9d; guidArray[i] = Guid.NewGuid(); stringDateTimeArray[i] = DateTime.Now.ToString(formatProvider); dateTimeArray[i] = DateTime.Now; personArray[i] = new Person { Id = Guid.NewGuid(), Name = "Test Name " + i, Age = i % 85, Length = 1.70m + ((i % 20) / 100m), BirthDate = DateTime.Now.AddDays(i) }; personStringArray[i] = new PersonStringDto { Id = Guid.NewGuid().ToString(), Name = "Test Name " + i, Age = (i % 85).ToString(CultureInfo.CurrentCulture), Length = (1.70m + ((i % 20) / 100m)).ToString(CultureInfo.CurrentCulture), BirthDate = DateTime.Now.AddDays(i).ToString(CultureInfo.CurrentCulture) }; customerArray[i] = CustomerFactory.CreateTestCustomer(); customerDtoArray[i] = TypeAdapter.Adapt <CustomerDto>(customerArray[i]); addressArray[i] = new Address { Id = i, City = "Gbg", Country = "Sweden", Street = "Street 1" }; benchSourceArray[i] = benchSource; displayResourceEnumArray[i] = (DisplayAttributeResourceEnum)(i % 4); displayResxEnumArray[i] = (DisplayAttributeResxEnum)(i % 4); displayEnumArray[i] = (DisplayAttributeEnum)(i % 4); descriptionEnumArray[i] = (DescriptionAttributeEnum)(i % 4); int32EnumArray[i] = (Int32Enum)(i % 4); } // FromString conversions //this.ProfileConvert<string, Guid>(stringGuidArray, formatProvider, i => new Guid(stringGuidArray[i])); this.ProfileConvert <string, int>(stringIntArray, formatProvider, i => int.Parse(stringIntArray[i], formatProvider)); //this.ProfileConvert<string, string>(stringIntArray, formatProvider, i => stringIntArray[i].Clone()); //this.ProfileConvert<string, DateTime>(stringDateTimeArray, formatProvider, i => Convert.ToDateTime(stringDateTimeArray[i])); //this.ProfileConvert<string, decimal>(stringDecimalArray, formatProvider, i => StringParser.TryParseDecimal(stringDecimalArray[i], formatProvider)); //this.ProfileConvert<int, ExampleEnum>(intArray, formatProvider, null); //this.ProfileConvert<double, decimal>(doubleArray, formatProvider, i => Convert.ToDecimal(doubleArray[i])); //this.ProfileConvert<decimal, double>(decimalArray, formatProvider, i => Convert.ToDouble(decimalArray[i])); //this.ProfileConvert<int, string>(intArray, formatProvider, i => intArray[i].ToString(formatProvider)); /*this.ProfileConvert<int, int>(intArray, formatProvider, i => Convert.ChangeType(i, typeof(int))); * * this.ProfileConvert<decimal, string>(decimalArray, formatProvider, i => decimalArray[i].ToString(formatProvider)); * * this.ProfileConvert<Guid, string>(guidArray, CultureInfo.CurrentCulture, i => guidArray[i].ToString()); * * this.ProfileConvert<DateTime, string>(dateTimeArray, CultureInfo.CurrentCulture, i => dateTimeArray[i].ToString()); */ //this.ProfileConvert<PersonStringDto, Person>(personStringArray, CultureInfo.CurrentCulture, null); //this.ProfileConvert<Customer, CustomerDto>(customerArray, CultureInfo.CurrentCulture, null); //this.ProfileConvert<CustomerDto, Customer>(customerDtoArray, CultureInfo.CurrentCulture, null); //this.ProfileConvert<BenchSource, BenchDestination>(benchSourceArray, CultureInfo.CurrentCulture, null); //this.ProfileConvert<Address, AddressDto>(addressArray, CultureInfo.CurrentCulture, null); //this.ProfileConvert<Person, PersonStringDto>(personArray, CultureInfo.CurrentCulture, null); //this.ProfileConvert<Person, PersonDto>(personArray, CultureInfo.CurrentCulture, null); //this.ProfileConvert<Person, PersonStruct>(personArray, CultureInfo.CurrentCulture, null); //this.ProfileConvert<int, decimal>(intArray, formatProvider, i => Convert.ToDecimal(intArray[i], formatProvider)); /* * this.ProfileConvert<DisplayAttributeResourceEnum, string>(displayResourceEnumArray, CultureInfo.CurrentCulture, null); * this.ProfileConvert<DisplayAttributeResxEnum, string>(displayResxEnumArray, CultureInfo.CurrentCulture, null); * this.ProfileConvert<DisplayAttributeEnum, string>(displayEnumArray, CultureInfo.CurrentCulture, null); * this.ProfileConvert<DescriptionAttributeEnum, string>(descriptionEnumArray, CultureInfo.CurrentCulture, null); * this.ProfileConvert<Int32Enum, string>(int32EnumArray, CultureInfo.CurrentCulture, null); */ }
static long BenchEmitMapper(int mappingsCount) { var s = new BenchSource(); var d = new BenchDestination(); var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < mappingsCount; ++i) { emitMapper.Map(s, d); } sw.Stop(); return sw.ElapsedMilliseconds; }
static long BenchEmitMapper(int mappingsCount) { var mapper = ObjectMapperManager.DefaultInstance.GetMapper<BenchSource, BenchDestination>(); var s = new BenchSource(); var d = new BenchDestination(); var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < mappingsCount; ++i) { mapper.Map(s, d); } sw.Stop(); return sw.ElapsedMilliseconds; }
public void MapperTimeTest() { const int hm = 100000; var from = new ModelFrom(); var sw = new Stopwatch(); sw.Start(); AutoMapper.Mapper.CreateMap <ModelFrom, ModelTo>() .ForMember(x => x.BoolNullTo, opt => opt.MapFrom(x => x.BoolNullFrom)) .ForMember(x => x.BoolTo, opt => opt.MapFrom(x => x.BoolFrom)) .ForMember(x => x.IntNullTo, opt => opt.MapFrom(x => x.IntNullFrom)) .ForMember(x => x.IntTo, opt => opt.MapFrom(x => x.BoolFrom ? 1 : 70)) .ForMember(x => x.StringTo, opt => opt.MapFrom(x => x.StringFrom)) .ForMember(x => x.TypeTo, opt => opt.MapFrom(x => x.TypeFrom)); AutoMapper.Mapper.CreateMap <BenchSource, BenchDestination>(); sw.Stop(); Console.WriteLine("AutoMapper prepare test Time in ms : {0} ms", sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); Mapper.CreateMap <ModelTo, ModelFrom>() .ForMember(x => x.BoolNullTo, opt => opt.MapFrom(x => x.BoolNullFrom)) .ForMember(x => x.BoolTo, opt => opt.MapFrom(x => x.BoolFrom)) .ForMember(x => x.IntNullTo, opt => opt.MapFrom(x => x.IntNullFrom)) .ForMember(x => x.IntTo, opt => opt.MapFrom(x => x.BoolFrom ? 1 : 70)) .ForMember(x => x.StringTo, opt => opt.MapFrom(x => x.StringFrom)) .ForMember(x => x.TypeTo, opt => opt.MapFrom(x => x.TypeFrom)); Mapper.CreateMap <BenchDestination, BenchSource>(); Mapper.Build(); sw.Stop(); Console.WriteLine("AleaMapper prepare test Time in ms : {0} ms", sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); for (int i = 0; i < hm; i++) { AutoMapper.Mapper.Map <ModelTo>(from); } sw.Stop(); Console.WriteLine("AutoMapper Test on {1} pcs Time in ms : {0}ms\n Time on one pcs : {2} Ticks", sw.ElapsedMilliseconds, hm, (sw.ElapsedTicks / hm)); sw.Reset(); sw.Start(); for (int i = 0; i < hm; i++) { HandmadeMap(from); } sw.Stop(); Console.WriteLine("Handmade Test on {1} pcs Time in ms : {0}ms\n Time on one pcs : {2} Ticks", sw.ElapsedMilliseconds, hm, (sw.ElapsedTicks / hm)); sw.Reset(); sw.Start(); for (int i = 0; i < hm; i++) { Mapper.Map <ModelTo, ModelFrom>(from); } sw.Stop(); Console.WriteLine("AleaMapper Test on {1} pcs Time in ms : {0}ms\n Time on one pcs : {2} Ticks", sw.ElapsedMilliseconds, hm, (sw.ElapsedTicks / hm)); sw.Reset(); Func <ModelFrom, ModelTo> dd; sw.Start(); for (int i = 0; i < hm; i++) { dd = Mapper.Map <ModelTo, ModelFrom>(); } sw.Stop(); Console.WriteLine("AleaMapper Inline getter Test on {1} pcs Time in ms : {0}ms\n Time on one pcs : {2} Ticks", sw.ElapsedMilliseconds, hm, (sw.ElapsedTicks / hm)); sw.Reset(); var del = Mapper.Map <ModelTo, ModelFrom>(); sw.Start(); for (int i = 0; i < hm; i++) { del(from); } sw.Stop(); Console.WriteLine("AleaMapper Inline Test on {1} pcs Time in ms : {0}ms\n Time on one pcs : {2} Ticks", sw.ElapsedMilliseconds, hm, (sw.ElapsedTicks / hm)); #region EmitMapper part test sw.Reset(); sw.Start(); var bench = new BenchSource(); for (int i = 0; i < hm; i++) { Mapper.Map <BenchDestination, BenchSource>(bench); } sw.Stop(); Console.WriteLine("AleaMapper Test on {1} pcs Time in ms : {0}ms\n Time on one pcs : {2} Ticks", sw.ElapsedMilliseconds, hm, (sw.ElapsedTicks / hm)); #endregion }
private static long BenchOoMapper(int mappingsCount) { var s = new BenchSource(); var d = new BenchDestination(); return Benchmark(mappingsCount, () => d = Mapper.Map(s, d)); }