Ejemplo n.º 1
0
 private static Func <ComplexSourceType, ComplexDestinationType, ComplexDestinationType> GetFunc()
 {
     return((src, dest) =>
     {
         dest.ID = src.ID;
         if (src.Complex != null)
         {
             var complexSource = src.Complex;
             var complexDestination = new NestedDestinationType();
             complexDestination.ID = complexSource.ID;
             complexDestination.Name = complexSource.Name;
             dest.Complex = complexDestination;
         }
         return dest;
     });
 }
Ejemplo n.º 2
0
        static void Benchmark()
        {
            var mapper = new MemberMapper();

            var map = mapper.CreateMapProposal <ComplexSourceType, ComplexDestinationType>(customMapping: src => new ComplexDestinationType
            {
                ID = Enumerable.Range(0, 100000).Count()
            }).FinalizeMap();


            var source = new ComplexSourceType
            {
                ID      = 5,
                Complex = new NestedSourceType
                {
                    ID   = 10,
                    Name = "test"
                }
            };

            source = null;
            f      = (src, dest) =>

            {
                dest.ID = src.ID;
                if (src.Complex != null)
                {
                    var complexSource      = src.Complex;
                    var complexDestination = new NestedDestinationType();
                    complexDestination.ID   = Enumerable.Range(0, 100000).Count();
                    complexDestination.Name = complexSource.Name;
                    dest.Complex            = complexDestination;
                }
                return(dest);
            };

            var sw = Stopwatch.StartNew();

            const int iterations = 100;

            for (int i = 0; i < iterations; i++)
            {
                Foo = new ComplexDestinationType();

                Foo.ID = source.ID;
                if (source.Complex != null)
                {
                    var complexSource      = source.Complex;
                    var complexDestination = new NestedDestinationType();
                    complexDestination.ID   = Enumerable.Range(0, 100000).Count();
                    complexDestination.Name = complexSource.Name;
                    Foo.Complex             = complexDestination;
                }
            }

            sw.Stop();

            Console.WriteLine("Manual " + sw.Elapsed);

            sw.Restart();

            for (int i = 0; i < iterations; i++)
            {
                Foo = f(source, new ComplexDestinationType());
            }

            sw.Stop();

            Console.WriteLine("Func " + sw.Elapsed);

            sw.Restart();

            for (int i = 0; i < iterations; i++)
            {
                Foo = mapper.Map <ComplexSourceType, ComplexDestinationType>(source);
            }

            sw.Stop();

            Console.WriteLine("Map " + sw.Elapsed);

            var func = (Func <ComplexSourceType, ComplexDestinationType, ComplexDestinationType>)map.MappingFunction;

            var destination = new ComplexDestinationType();

            sw.Restart();

            for (int i = 0; i < iterations; i++)
            {
                Foo = func(source, new ComplexDestinationType());
            }

            sw.Stop();

            Console.WriteLine("Map 1 " + sw.Elapsed);
        }
Ejemplo n.º 3
0
 private static Func<ComplexSourceType, ComplexDestinationType, ComplexDestinationType> GetFunc()
 {
     return (src, dest) =>
       {
     dest.ID = src.ID;
     if (src.Complex != null)
     {
       var complexSource = src.Complex;
       var complexDestination = new NestedDestinationType();
       complexDestination.ID = complexSource.ID;
       complexDestination.Name = complexSource.Name;
       dest.Complex = complexDestination;
     }
     return dest;
       };
 }
Ejemplo n.º 4
0
        static void Benchmark()
        {
            var mapper = new MemberMapper();

              var map = mapper.CreateMap(typeof(ComplexSourceType), typeof(ComplexDestinationType)).FinalizeMap();

              var source = new ComplexSourceType
              {
            ID = 5,
            Complex = new NestedSourceType
            {
              ID = 10,
              Name = "test"
            }
              };

              Func<ComplexSourceType, ComplexDestinationType, ComplexDestinationType> f = (src, dest) =>
              {
            dest.ID = src.ID;
            if (src.Complex != null)
            {
              var complexSource = src.Complex;
              var complexDestination = new NestedDestinationType();
              complexDestination.ID = complexSource.ID;
              complexDestination.Name = complexSource.Name;
              dest.Complex = complexDestination;
            }
            return dest;
              };

              var sw = Stopwatch.StartNew();

              for (int i = 0; i < 1000000; i++)
              {
            Foo = new ComplexDestinationType();

            Foo.ID = source.ID;
            if (source.Complex != null)
            {
              var complexSource = source.Complex;
              var complexDestination = new NestedDestinationType();
              complexDestination.ID = complexSource.ID;
              complexDestination.Name = complexSource.Name;
              Foo.Complex = complexDestination;
            }
              }

              sw.Stop();

              Console.WriteLine(sw.Elapsed);

              sw.Restart();

              for (int i = 0; i < 1000000; i++)
              {
            Foo = f(source, new ComplexDestinationType());
              }

              sw.Stop();

              Console.WriteLine(sw.Elapsed);

              sw.Restart();

              for (int i = 0; i < 1000000; i++)
              {
            Foo = mapper.Map<ComplexSourceType, ComplexDestinationType>(source);
              }

              sw.Stop();

              Console.WriteLine(sw.Elapsed);

              var func = (Func<ComplexSourceType, ComplexDestinationType, ComplexDestinationType>)map.MappingFunction;

              var destination = new ComplexDestinationType();

              sw.Restart();

              for (int i = 0; i < 1000000; i++)
              {
            Foo = func(source, new ComplexDestinationType());
              }

              sw.Stop();

              Console.WriteLine(sw.Elapsed);
        }