public void MapperMethod() {

            AutoMapperInit();

            StudentDo xiaoming = new StudentDo() { StudentName = "小明", Age = 10 };
            SchoolDo xiaoxue = new SchoolDo() { SchoolName = "义津小学", Address = "安徽安庆枞阳" };
            ClassDo banji_01 = new ClassDo() { ClassName = "401班", ClassLevel = 1, StudentNum = 50 };
            xiaoxue.ClassInfo = banji_01;

            SchoolDo zhongxue = new SchoolDo() { SchoolName = "义津中学", Address = "安徽安庆枞阳" };
            ClassDo banji_02 = new ClassDo() { ClassName = "501班", ClassLevel = 2, StudentNum = 50 };
            zhongxue.ClassInfo = banji_02;

            xiaoming.SmallSchool = xiaoxue;
            xiaoming.MiddleSchool = zhongxue;

            Stopwatch watcher = new Stopwatch();
            watcher.Start();
            for (var i = 0; i < 100000; i++) {
                var xiaohong = AutoMapper.Mapper.Map<StudentDo, StudentDto>(xiaoming);
            }
            watcher.Stop();
            long time1 = watcher.ElapsedMilliseconds;
            Console.WriteLine("共花费{0}毫秒", time1);

            watcher.Reset();
            watcher.Restart();

            ObjectsMapper<StudentDo, StudentDto> mapper = new ObjectMapperManager().GetMapper<StudentDo, StudentDto>(new DefaultMapConfig());
            StudentDto xiaofang = null;
            for (var i = 0; i < 1000000; i++) {
                xiaofang = mapper.Map(xiaoming);
            }
            long time2 = watcher.ElapsedMilliseconds;
            Console.WriteLine("共花费{0}毫秒", time2);

            System.Threading.Thread.Sleep(5000);

            Console.ReadLine();

        }
Exemple #2
0
        public void MapperMethod()
        {
            AutoMapperInit();

            StudentDo xiaoming = new StudentDo()
            {
                StudentName = "小明", Age = 10
            };
            SchoolDo xiaoxue = new SchoolDo()
            {
                SchoolName = "义津小学", Address = "安徽安庆枞阳"
            };
            ClassDo banji_01 = new ClassDo()
            {
                ClassName = "401班", ClassLevel = 1, StudentNum = 50
            };

            xiaoxue.ClassInfo = banji_01;

            SchoolDo zhongxue = new SchoolDo()
            {
                SchoolName = "义津中学", Address = "安徽安庆枞阳"
            };
            ClassDo banji_02 = new ClassDo()
            {
                ClassName = "501班", ClassLevel = 2, StudentNum = 50
            };

            zhongxue.ClassInfo = banji_02;

            xiaoming.SmallSchool  = xiaoxue;
            xiaoming.MiddleSchool = zhongxue;

            Stopwatch watcher = new Stopwatch();

            watcher.Start();
            for (var i = 0; i < 100000; i++)
            {
                var xiaohong = AutoMapper.Mapper.Map <StudentDo, StudentDto>(xiaoming);
            }
            watcher.Stop();
            long time1 = watcher.ElapsedMilliseconds;

            Console.WriteLine("共花费{0}毫秒", time1);

            watcher.Reset();
            watcher.Restart();

            ObjectsMapper <StudentDo, StudentDto> mapper = new ObjectMapperManager().GetMapper <StudentDo, StudentDto>(new DefaultMapConfig());
            StudentDto xiaofang = null;

            for (var i = 0; i < 1000000; i++)
            {
                xiaofang = mapper.Map(xiaoming);
            }
            long time2 = watcher.ElapsedMilliseconds;

            Console.WriteLine("共花费{0}毫秒", time2);

            System.Threading.Thread.Sleep(5000);

            Console.ReadLine();
        }