熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

.Net 3.5環境下常用數組性能測試

2022-06-13   來源: .NET編程 

  這件事情似乎很無聊但是沒人做我來做下苦力吧

  以下是一些簡單的測試單位以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


From:http://tw.wingwit.com/Article/program/net/201311/11505.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.