Dictionary性能之测试

添加二百万记录时间 16秒

用键查询值的平均时间,0MS

内存使用 150M

代码:
Dictionary<string,object>性能之测试Dictionary<string,object>性能之测试/**//*
Dictionary<string,object>性能之测试 * Created by 邹健
Dictionary<string,object>性能之测试 * Date: 2008-2-14
Dictionary<string,object>性能之测试 * Time: 10:21
Dictionary<string,object>性能之测试 * 
Dictionary<string,object>性能之测试 * 
Dictionary<string,object>性能之测试 
*/

Dictionary<string,object>性能之测试
namespace test
Dictionary<string,object>性能之测试Dictionary<string,object>性能之测试
Dictionary<string,object>性能之测试{
Dictionary<string,object>性能之测试    
using System;
Dictionary<string,object>性能之测试    
using System.Collections.Generic;
Dictionary<string,object>性能之测试    
class Program
Dictionary<string,object>性能之测试Dictionary<string,object>性能之测试    
Dictionary<string,object>性能之测试{
Dictionary<string,object>性能之测试        
public static void Main(string[] args)
Dictionary<string,object>性能之测试Dictionary<string,object>性能之测试        
Dictionary<string,object>性能之测试{
Dictionary<string,object>性能之测试            GetTime();
Dictionary<string,object>性能之测试            Random r
= new Random();
Dictionary<string,object>性能之测试            Dictionary
<string,object> dict =new Dictionary<string,object>();
Dictionary<string,object>性能之测试            
for(int i=1 ;i<2000000; i++)
Dictionary<string,object>性能之测试                dict.Add(i.ToString(),i
+r.Next(1000));
Dictionary<string,object>性能之测试            GetTime();
Dictionary<string,object>性能之测试            
Dictionary<string,object>性能之测试Dictionary<string,object>性能之测试            
while(true)Dictionary<string,object>性能之测试{
Dictionary<string,object>性能之测试                GetTime(
"begin :");
Dictionary<string,object>性能之测试                
string input= Console.ReadLine();
Dictionary<string,object>性能之测试                
if(input.ToLower()=="end"break;
Dictionary<string,object>性能之测试                
if(dict.ContainsKey(input))
Dictionary<string,object>性能之测试                Console.Write(
"result is "+ dict[input]);
Dictionary<string,object>性能之测试                GetTime(
"end :");
Dictionary<string,object>性能之测试            }

Dictionary<string,object>性能之测试            
Dictionary<string,object>性能之测试            Console.Write(
"Press any key to continue . . . ");
Dictionary<string,object>性能之测试            Console.ReadKey(
true);
Dictionary<string,object>性能之测试        }

Dictionary<string,object>性能之测试Dictionary<string,object>性能之测试        
static void  GetTime()Dictionary<string,object>性能之测试{
Dictionary<string,object>性能之测试            GetTime(
"当前时间");
Dictionary<string,object>性能之测试        }

Dictionary<string,object>性能之测试Dictionary<string,object>性能之测试                
static void  GetTime(string str)Dictionary<string,object>性能之测试{
Dictionary<string,object>性能之测试            Console.WriteLine(str 
+ DateTime.Now.ToString("mm:ss:fff"));
Dictionary<string,object>性能之测试        }

Dictionary<string,object>性能之测试    }

Dictionary<string,object>性能之测试}

上一篇:求数组中只出现一次的数字(算法)


下一篇:搬家通知博文地址(将博客搬到CSDN)