zoukankan      html  css  js  c++  java
  • .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倍

  • 相关阅读:
    CentOS 5.5 系统安全配置
    从PHP5.2.x迁移到PHP5.3.x
    快要放假了!但为什么现在感到特别的累呢?!
    C#、Oracle、Sql server中拼音查询的函数
    C#实现Word中表格信息读取
    用 win2003 架设共享服务器[3]
    用 win2003 架设共享服务器[2]
    用 win2003 架设共享服务器[1]
    c#操作word表格
    Visual Studio 2008(VS2008)升级正式版
  • 原文地址:https://www.cnblogs.com/hnzheng/p/12775020.html
Copyright © 2011-2022 走看看