zoukankan      html  css  js  c++  java
  • 如何查看自制词典的执行效率

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Diagnostics;
    
    namespace _EditDictionary
    {
        class KeyValuePair
        {
            public KeyValuePair()
            {
            
            }
    
            public KeyValuePair(string key,string value)
            {
                this.key = key;
                this.value = value;
            }
            private string key;
            public string Key
            {
                 get { return key; }
                 set { key = value; }
            }
        
            private string value;
            public string Value
            {
                get { return this.value; }
                set { this.value = value; }
            }
    
    
        }
    
        class Mydic
        {
            List<KeyValuePair> list = new List<KeyValuePair>();
    
            public void Add(string key, string value)
            {
                list.Add(new KeyValuePair(key,value));
            }
    
            public bool ContainKey(string key)
            { 
                bool result=false;
                foreach(KeyValuePair kvp in list)
                {
                    if (kvp.Key == key)
                    {
                        result = true;
                      //  value += kvp.Value ;                  
                        break;
                    }
                }
                return result;        
            }
            
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                
              
                Mydic dic = new Mydic();
                string[] arr = File.ReadAllLines(@"D:英汉词典TXT格式.txt", Encoding.Default);//第二个参数是防止乱码;第一个参数是字典的txt文档(找一个大的txt字典,测试程序才能更有效)
    
                foreach(string item in arr)
                {
                    //分割出单词和解释
                    string[] strArr = item.Split(new char[]{' '},StringSplitOptions.RemoveEmptyEntries);
    
                    if (strArr.Length == 2)
                    { 
                        if(!dic.ContainKey(strArr[0]))
                        {
                            dic.Add(strArr[0],strArr[1]);
                        }
                    }
                }
    
                Stopwatch sw = new Stopwatch();
                sw.Start();
                dic.ContainKey("china");
                sw.Stop();
                Console.WriteLine(sw.Elapsed);
                Console.WriteLine();
                Console.Read();
    
            }
        }
    }
    

    耗时: 

     

  • 相关阅读:
    Android数据存储之Application
    contentOffset、contentSize和contentInset
    block
    IOS中的深拷贝和浅拷贝
    手势图的设计原理(2)拖拽、捏合、轻扫、旋转
    深浅拷贝的应用-copy、mutableCopy
    手势图的设计原理(1)建立、开始、移动、结束、点击、长按
    UIView
    MVC-Model
    UIPageControl页面控制的控件
  • 原文地址:https://www.cnblogs.com/5696-an/p/4995687.html
Copyright © 2011-2022 走看看