2024年4月28日发(作者:)

using stics;

namespace WebApp

{

class Program

{

static Hashtable _hashtable;

static Dictionary _dictionary;

static ConcurrentDictionary _conDictionary;

static void Main(string[] args)

{

Compare(5000000);

ne();

();

}

public static void Compare(int dataCount)

{

_hashtable = new Hashtable();

_dictionary = new Dictionary();

_conDictionary=new ConcurrentDictionary();

Stopwatch stopWatch = new Stopwatch();

// Hashtable

();

for (int i = 0; i < dataCount; i++)

{

_("key" + ng(), "Value" + ng());

}

();

ine("HashTable插" + dataCount + "条耗时(毫秒):" + dMilliseconds);

//Dictionary

();

();

for (int i = 0; i < dataCount; i++)

{

_("key" + ng(), "Value" +ng());

}

();

ine("Dictionary插" + dataCount + "条耗时(毫秒):" + dMilliseconds);

//ConcurrentDictionary

();

();

for (int i = 0; i < dataCount; i++)

{

_("key" + ng(), "Value" + ng());

}

();

ine("ConcurrentDictionary插" + dataCount + "条耗时(毫秒):" + dMilliseconds);

// Hashtable

();

();

for (int i = 0; i < _; i++)

{

var key = _hashtable[i];

}

();

ine("HashTable遍历时间(毫秒):" + dMilliseconds);

//Dictionary

();

();

for (int i = 0; i < _; i++)

{

var key = _dictionary["key" + ng()];

}

();

ine("Dictionary遍历时间(毫秒):" + dMilliseconds);

//ConcurrentDictionary

();

();

for (int i = 0; i < _; i++)

{

var key = _conDictionary["key"+ng()];

}

();

ine("ConcurrentDictionary遍历时间(毫秒):" + dMilliseconds);

}

}

}