码迷,mamicode.com
首页 > 其他好文 > 详细

字符串匹配 对比系统自带函数

时间:2017-06-21 14:10:04      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:substr   watch   技术分享   bcd   bcb   images   ring   tar   void   

 public static int IndexOf(string chars,string str) {
            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] != chars[0]) continue;
                if (i + (chars.Length ) > str.Length)
                    return -1;
                if (str.Substring(i, chars.Length) == chars) return i;
            }
            return -1;
        }

    static void Main(string[] args)
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();
            for (int i = 0; i < 200000; i++)
                IndexOf("abcsdas", "bcbabcbsbssadasdasdasdabcdabcbabcbsbssadasdasdasdabcdabcbabcbsbssadasdasdasdabcdabcbabcbsbssadasdasdasdabcdabcbabcbsbssadasdasdasdabcdabcbabcbsbssadasdasdasdabcdabcbabcbsbssadasdasdasdabcda");
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);
            sw = new Stopwatch();
            sw.Start();
            for (int i = 0; i < 200000; i++)
                "bcbabcbsbssadasdasdasdabcdabcbabcbsbssadasdasdasdabcdabcbabcbsbssadasdasdasdabcdabcbabcbsbssadasdasdasdabcdabcbabcbsbssadasdasdasdabcdabcbabcbsbssadasdasdasdabcdabcbabcbsbssadasdasdasdabcda".IndexOf("abcsdas");
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);

            Console.Read();
        }

  技术分享

 

技术分享

 

字符串匹配 对比系统自带函数

标签:substr   watch   技术分享   bcd   bcb   images   ring   tar   void   

原文地址:http://www.cnblogs.com/ProDoctor/p/7058589.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!