打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Dictionary<string,object>性能之测试
添加二百万记录时间 16秒

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

内存使用 150M

代码:
/*
 * Created by 邹健
 * Date: 2008-2-14
 * Time: 10:21
 * 
 * 
 
*/

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

            
            Console.Write(
"Press any key to continue . . . ");
            Console.ReadKey(
true);
        }

        
static void  GetTime(){
            GetTime(
"当前时间");
        }

                
static void  GetTime(string str){
            Console.WriteLine(str 
+ DateTime.Now.ToString("mm:ss:fff"));
        }

    }

}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C# Dictionary 终极使用方法
C#容器使用 学习ASP.Net之Collections下的容器类
【新提醒】【小贱学C#笔记之Newtonsoft.Json(三)】
c# – 将字符串分隔到不在集合字典中的列表中
BP网络模型的实现(C#)
C# 递归算法!(n多举例)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服