コード例 #1
0
        private static void MeasureCachedWaylessInstanceNestedMap()
        {
            PersonNested person = PersonNested.Create();

            person.NestedPerson = Person.Create();

            Stopwatch stopwatch = Stopwatch.StartNew();
            var       mapper    = _waymore
                                  .SetRules <PersonDTONested, PersonNested>(rules =>
            {
                var nm = _waymore.Get <PersonDTO, Person>();
                rules.FieldMap(x => x.NestedPersonDTO, x => nm.Map(x.NestedPerson));
            })
                                  .Get <PersonDTONested, PersonNested>();

            for (int i = 0; i < Iterations; i++)
            {
                var personDtoNested = mapper.Map(person);
            }

            stopwatch.Stop();
            Console.WriteLine("Wayless (Nested): {0}ms", stopwatch.Elapsed.TotalMilliseconds);

            Stopwatch stopwatch2 = Stopwatch.StartNew();

            var nestedMapper = _waymore.Get <PersonDTO, Person>();
            var mapper2      = _waymore
                               .SetRules <PersonDTONested, PersonNested>(rules =>
            {
                rules.FieldMap(x => x.NestedPersonDTO, x => nestedMapper.Map(x.NestedPerson))
                .FinalizeRules();
            })
                               .Get <PersonDTONested, PersonNested>();


            for (int i = 0; i < Iterations; i++)
            {
                var personDtoNested = mapper2.Map(person);
            }

            stopwatch2.Stop();
            Console.WriteLine("Wayless (Nested2): {0}ms", stopwatch2.Elapsed.TotalMilliseconds);
        }