Пример #1
0
        static void Test_EmitMapperResult()
        {
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            var mapper = ObjectMapperManager.DefaultInstance.GetMapper <BenchSource, BenchDestination>();
            var src    = new BenchSource();

            Console.WriteLine("mapping and serializing...");
            for (int i = 100; i > 0; i--)
            {
                src.i1.i1.i = i;
                src.s1      = "s1_" + i;
                var dd = mapper.Map(src);
                SaveToFile(dd);
            }

            //
            Console.WriteLine("deserializing...");
            var dest = new BenchDestination();

            foreach (string str in File.ReadAllLines(filePath))
            {
                dest = JsonConvert.DeserializeObject <BenchDestination>(str);
                Console.WriteLine("dest.i1.i1.i:{0},dest.s1:{1}", dest.i1.i1.i, dest.s1);
            }
        }
Пример #2
0
        static void Test_HandwrittenMapper(int mappingsCount)
        {
            var src  = new BenchSource();
            var dest = new BenchDestination();
            var sw   = new Stopwatch();

            sw.Start();
            for (int i = 0; i < mappingsCount; i++)
            {
                dest = HandwrittenMapper.Map(src, dest);
                //JsonConvert.SerializeObject(dest);
            }
            sw.Stop();

            PrintResult(mappingsCount, "Handwritten", sw.ElapsedMilliseconds);
        }
Пример #3
0
        static void Test_EmitMapper(int mappingsCount)
        {
            var mapper = ObjectMapperManager.DefaultInstance.GetMapper <BenchSource, BenchDestination>();
            var src    = new BenchSource();
            var dest   = new BenchDestination();
            var sw     = new Stopwatch();

            sw.Start();
            for (int i = 0; i < mappingsCount; i++)
            {
                mapper.Map(src, dest);
            }
            sw.Stop();

            PrintResult(mappingsCount, "EmitMapper", sw.ElapsedMilliseconds);
        }
Пример #4
0
        static void Test_AutoMapper(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();

            PrintResult(mappingsCount, "AutoMapper", sw.ElapsedMilliseconds);
        }
Пример #5
0
        public static BenchDestination Map(BenchSource src, BenchDestination dest)
        {
            if (src == null)
            {
                return(null);
            }
            if (dest == null)
            {
                dest = new BenchDestination();
            }
            dest.i1 = Map(src.i1, dest.i1);
            dest.i2 = Map(src.i2, dest.i2);
            dest.i3 = Map(src.i3, dest.i3);
            dest.i4 = Map(src.i4, dest.i4);
            dest.i5 = Map(src.i5, dest.i5);
            dest.i6 = Map(src.i6, dest.i6);
            dest.i7 = Map(src.i7, dest.i7);
            dest.i8 = Map(src.i8, dest.i8);

            dest.n2 = src.n2;
            dest.n3 = src.n3;
            dest.n4 = src.n4;
            dest.n5 = src.n5;
            dest.n6 = src.n6;
            dest.n7 = src.n7;
            dest.n8 = src.n8;
            dest.n9 = src.n9;

            dest.s1 = src.s1;
            dest.s2 = src.s2;
            dest.s3 = src.s3;
            dest.s4 = src.s4;
            dest.s5 = src.s5;
            dest.s6 = src.s6;
            dest.s7 = src.s7;

            return(dest);
        }
Пример #6
0
        static void SaveToFile(BenchDestination dest)
        {
            var txt = JsonConvert.SerializeObject(dest);

            File.AppendAllText("dest.txt", txt + "\r\n");
        }