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倍

  • 相关阅读:
    Cocos2d-x 学习笔记(11.1) MoveBy MoveTo
    Cocos2d-x 学习笔记(10) ActionInstant
    Cocos2d-x 学习笔记(9) Action 运行原理
    Cocos2d-x 学习笔记(8) ActionManager
    Cocos2d-x 学习笔记(7) 内存管理 Sprite SpriteFrame Texture2D
    Cocos2d-x 学习笔记(6) Sprite SpriteFrameCache Texture2D TextureCache
    常见串口术语区分
    串口调试
    Linux
    缓冲区
  • 原文地址:https://www.cnblogs.com/hnzheng/p/12775020.html
Copyright © 2011-2022 走看看