• .Net Core 和 .Net Framework 对比01


    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace 接口和类
    {
        class Program
        {
            static void Main(string[] args)
            {
                Stopwatch stopwatch = new Stopwatch();
                const int seed = int.MaxValue;
    
                Children children = new Children();
                IChildern childern1 = new Children();
    
                Achdren abChildren = new Achdren();
                AbChildren abChildren1 = new Achdren();
    
                for (int j = 0; j < 10; j++)
                {
                    stopwatch.Restart();
                    for (int i = 0; i < seed; i++)
                    {
                        children.Do();
    
                    }
                    Console.WriteLine($"Children直接调用{stopwatch.ElapsedMilliseconds}");
                    stopwatch.Restart();
                    for (int i = 0; i < seed; i++)
                    {
                        childern1.Do();
    
                    }
                    Console.WriteLine($"IChildern接口调用{stopwatch.ElapsedMilliseconds}");
                    stopwatch.Restart();
    
                    stopwatch.Start();
                    for (int i = 0; i < seed; i++)
                    {
                        abChildren.Do();
    
                    }
                    Console.WriteLine($"Achdren直接调用{stopwatch.ElapsedMilliseconds}");
                    stopwatch.Restart();
                    for (int i = 0; i < seed; i++)
                    {
                        abChildren1.Do();
                       
                    }
                    Console.WriteLine($"AbChildren基类接口{stopwatch.ElapsedMilliseconds}");
                   // stopwatch.Restart();
                    Console.WriteLine($"
    ");
                }
                Console.ReadLine();
            }
        }
    
    
    
        public interface IChildern
        {
            void Do();
        }
        public class Children : IChildern
        {
            public void Do()
            {
    
            }
        }
    
    
        public abstract class AbChildren
        {
            public  abstract  void Do();
        }
        public class Achdren : AbChildren
        {
            public override void Do()
            {
                
            }
    
        }
    
    }

    同一段代码在 core 和framework 下执行对比,速度快了将近5倍

  • 相关阅读:
    20200503:对象头具体包括什么
    20200504:对象怎么定位
    [WC2006]水管局长
    [HNOI2010]弹飞绵羊
    [国家集训队]Tree II
    [SDOI2008]洞穴勘测
    [SDOI2011]染色
    [BZOJ2959]长跑
    LCT感性瞎扯
    [BZOJ4998]星球联盟
  • 原文地址:https://www.cnblogs.com/hnzheng/p/12775020.html
Copyright © 2020-2023  润新知