c#

位置:IT落伍者 >> c# >> 浏览文章

.Net 3.5环境下常用数组性能测试


发布日期:2020年10月17日
 
.Net 3.5环境下常用数组性能测试

这件事情似乎很无聊但是没人做我来做下苦力吧

以下是一些简单的测试单位以ms计算注意里面用到循环的数量有些事W有些是W

这些记录可以作为编程过程中的一些参考

测试平台

奔腾G 双核CPU

G内存

vs 调试环境测试

ArrayList (WW)

Stopwatch timer = new Stopwatch();

timerStart();

SystemCollectionsArrayList al = new SystemCollectionsArrayList();

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

{

alAdd(i);

}

timerStop();

ConsoleWrite(timerElapsedMillisecondsToString() + \t);

Stopwatch timer = new Stopwatch();

timerStart();

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

{

alContains(i);

}

timerStop();

ConsoleWriteLine(timerElapsedMillisecondsToString());

Hashtable (WW)

Stopwatch timer = new Stopwatch();

timerStart();

SystemCollectionsHashtable ht = new SystemCollectionsHashtable();

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

{

htAdd(i i);

}

timerStop();

ConsoleWrite(timerElapsedMillisecondsToString() + \t);

Stopwatch timer = new Stopwatch();

timerStart();

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

{

htContainsKey(i);

}

timerStop();

ConsoleWriteLine(timerElapsedMillisecondsToString());

}

把timer提高到万(Hashtable (WW))

HashSet (WW)

Stopwatch timer = new Stopwatch();

timerStart();

SystemCollectionsGenericHashSet ht = new SystemCollectionsGenericHashSet();

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

{

htAdd(i);

}

timerStop();

ConsoleWrite(timerElapsedMillisecondsToString() + \t);

Stopwatch timer = new Stopwatch();

timerStart();

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

{

htContains(i);

}

timerStop();

ConsoleWriteLine(timerElapsedMillisecondsToString());

List (WW)

Stopwatch timer = new Stopwatch();

timerStart();

SystemCollectionsGenericList ht = new SystemCollectionsGenericList();

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

{

htAdd(i);

}

timerStop();

ConsoleWrite(timerElapsedMillisecondsToString() + \t);

Stopwatch timer = new Stopwatch();

timerStart();

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

{

htContains(i);

}

timerStop();

ConsoleWriteLine(timerElapsedMillisecondsToString());

把List换成List

上一篇:C# 乱码解决

下一篇:漫谈.Net开发关于命名空间和目录划分