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倍

  • 相关阅读:
    Linux学习之网络基础
    C# 随笔
    最牛B的编码套路
    c++ Primer 第七章不熟悉知识点总结
    oracle求表的倒数二行数据
    c++ Primer 第六章不熟悉知识点总结
    c++ Primer 第五章不熟悉知识点总结
    c++ Primer 第四章不熟悉知识点总结
    c++ Primer 第三章不熟悉知识点总结
    骑驴找马
  • 原文地址:https://www.cnblogs.com/hnzheng/p/12775020.html
Copyright © 2011-2022 走看看