zoukankan      html  css  js  c++  java
  • 关于性能优化技巧

    一、关于Span的使用

    1.Span的最大优势:切片和堆栈空间及连续性

    所以在SubString这样的场景可以Span来做.

    2.Span的IndexOf(string)性能不如原生,注意使用Span.IndexOf(subSpan)

    using System;
    using System.Diagnostics;
    
    namespace SpanDemo
    {
        class Program
        {
            static void Main(string[] args)
            {
    
                string str = "wweidfidsjfkljsjdkljsdkjfsdlkj23423j4klsdlddssdsdsddjfl;sdjf;dsfjknxcvdjsofusd9-23432423423";
                ReadOnlySpan<char> strSapn = str.AsSpan();
    
                string subStr = "dsfjknxcvdjsofusd9";
               
    
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                for (int i = 0; i < 1000; i++)
                {
                    var subSpan = subStr.AsSpan();
                    strSapn.IndexOf(subSpan);
                }
                stopwatch.Stop();
    
    
    
                Console.WriteLine(stopwatch.Elapsed);
    
                stopwatch.Reset();
    
    
                stopwatch.Start();
                for (int i = 0; i < 1000; i++)
                {
                    str.IndexOf(subStr);
                }
                stopwatch.Stop();
                Console.WriteLine(stopwatch.Elapsed);
    
    
                Console.WriteLine("Hello World!");
                Console.ReadLine();
            }
    
            
        }
    }
    

      




    少侠,我看你气度不凡天赋异禀,这么帅,来了就给推荐一把吧




    我的最近更新
    最新发布文章、框架、咨询等,来看看吧
  • 相关阅读:
    String to Integer (atoi)
    Reverse Integer
    ZigZag Conversion
    01-GIT
    04-Eclipse操作SVN
    03-客户端访问SVN服务器
    02-Subversion安装与配置
    01-SVN概述
    09-Spring整合之SSH
    08-Spring的事务管理
  • 原文地址:https://www.cnblogs.com/humble/p/14317505.html
Copyright © 2011-2022 走看看