How to view the execution efficiency of a homemade dictionary

Source: Internet
Author: User

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 KeyVal             Uepair () {} 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) {Mydi            c dic = new Mydic (); string[] arr = file.readalllines (@ "d:\ English-Chinese dictionary txt format. txt", encoding.default);//The second argument is to prevent garbled characters; The first argument is the TXT document of the dictionary (find a large txt dictionary, Test program to be more effective) foreach (string item in arr) {//split word and explain 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 (); }    }}

Take:

 

How to view the execution efficiency of a homemade dictionary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.