<?xml version="1.0" encoding="UTF-8" ?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Loveyuki's BLOG - .NET 2.0 中 Hashtable 快速查找的方法</title><link>http://www.loveyuki.com/Comment/Index.aspxArticle/Faster_LookUP_HashTable_Net.aspx</link><language>zh-CN</language><webMaster>loveyuki@gmail.com</webMaster><pubDate>Sun, 21 Oct 2007 16:07:39 GMT</pubDate><copyright>Copyright 2007. All rights reserved.</copyright><generator>L-BLOG.NET, The Matrix Reloaded.</generator><image><title>Loveyuki's BLOG</title><url>http://www.loveyuki.com/Images/banner.gif</url><link>http://www.loveyuki.com/</link></image><item><link>http://www.loveyuki.com/Article/Faster_LookUP_HashTable_Net.aspx#CommentAnchor_76</link><title><![CDATA[评论：.NET 2.0 中 Hashtable 快速查找的方法]]></title><author>星辉一冷</author><pubDate>Sat, 24 Nov 2007 18:25:22 GMT</pubDate><guid>http://www.loveyuki.com/Article/Faster_LookUP_HashTable_Net.aspx#CommentAuchor_76</guid><description><![CDATA[Good work~<br />受教了~]]></description></item><item><link>http://www.loveyuki.com/Article/Faster_LookUP_HashTable_Net.aspx#CommentAnchor_1161</link><title><![CDATA[评论：.NET 2.0 中 Hashtable 快速查找的方法]]></title><author>ting</author><pubDate>Wed, 16 Apr 2008 13:14:26 GMT</pubDate><guid>http://www.loveyuki.com/Article/Faster_LookUP_HashTable_Net.aspx#CommentAuchor_1161</guid><description><![CDATA[2.0应该使用泛型的hashtable <br />以下代码运行时间<br />Execution time was 694511.1 microseconds.<br />Execution time was 971042.1 microseconds.<br />Execution time was 92339.1 microseconds.<br />可见有更强的速度<br /><br />Dictionary&lt;string, string&gt; dic = new Dictionary&lt;string, string&gt;();<br /> Hashtable objHash = new Hashtable();<br /> for (Int32 intI = 0; intI &lt; 1000000; intI++)<br /> {<br /> dic.Add(&quot;Key_&quot; + intI.ToString(), &quot;Value_&quot; + intI.ToString());<br /> objHash.Add(&quot;Key_&quot; + intI.ToString(), &quot;Value_&quot; + intI.ToString());<br /> }<br /> String strValue = String.Empty;<br /> Stopwatch timer = new Stopwatch();<br /> timer.Start();<br /> for (Int32 intI = 0; intI &lt; 1000000; intI++)<br /> {<br /> Object objValue = objHash[&quot;Key_&quot; + intI.ToString()];<br /> if (objValue != null)<br /> {<br /> strValue = (String)objValue;<br /> }<br /> }<br /> timer.Stop();<br /> Debug.WriteLine(string.Format(&quot;Execution time was {0:F1} microseconds.&quot;, timer.Elapsed.Ticks / 10m));<br /> timer.Reset();<br /> timer.Start();<br /> for (Int32 intI = 0; intI &lt; 1000000; intI++)<br /> {<br /> if (objHash.ContainsKey(&quot;Key_&quot; + intI.ToString()))<br /> {<br /> strValue = (String)objHash[&quot;Key_&quot; + intI.ToString()];<br /> }<br /> }<br /> timer.Stop();<br /> Debug.WriteLine(string.Format(&quot;Execution time was {0:F1} microseconds.&quot;, timer.Elapsed.Ticks / 10m));<br /> timer.Reset();<br /><br /> timer.Start();<br /> for (Int32 intI = 0; intI &lt; 100000; intI++)<br /> {<br /> if (dic.ContainsKey(&quot;Key_&quot; + intI.ToString()))<br /> {<br /> strValue = dic[&quot;Key_&quot; + intI.ToString()];<br /> }<br /> }<br /> timer.Stop();<br /> Debug.WriteLine(string.Format(&quot;Execution time was {0:F1} microseconds.&quot;, timer.Elapsed.Ticks / 10m));<br /> timer.Reset();]]></description></item></channel></rss>