1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| [STAThread]
static void Main(string[] args)
{
TestLists(100000);
}
static void TestLists(int max)
{
// CREATION DU SAMPLE DE TEST
string []sample = new string[max];
// c'est un tableau de chaine uniques (la liste des <max> premier naturels)
for(int i = 0; i < max; i++)
sample[i] = i.ToString();
// ma Hashtable de test
Hashtable myHT = new Hashtable();
// ajout
TimeSpan HTadd = TestAjout(myHT, max, sample);
Console.WriteLine("Hashtable - ajout : " + HTadd.ToString());
// recherche
TimeSpan HTsearch = TestRecherche(myHT, max);
Console.WriteLine("Hashtable - recherche : " + HTsearch.ToString());
// suppression
TimeSpan HTsuppr = TestSuppr(myHT, max);
Console.WriteLine("Hashtable - suppression : " + HTsuppr.ToString());
Console.ReadLine();
// ma ArrayList de test
ArrayList myAL = new ArrayList();
// ajout
TimeSpan ALadd = TestAjout(myAL, max, sample);
Console.WriteLine("ArrayList - ajout : " + HTadd.ToString());
// recherche
TimeSpan ALsearch = TestRecherche(myAL, max);
Console.WriteLine("ArrayList - recherche : " + ALsearch.ToString());
// suppression
TimeSpan ALsuppr = TestSuppr(myAL, max);
Console.WriteLine("ArrayList - suppression : " + ALsuppr.ToString());
Console.ReadLine();
// ajouter ici le code pour les List generiques
// ##################################
// #
// #
// ##################################
}
static TimeSpan TestAjout(IList list, int max, object[]sample)
{
// timestamp de départ
DateTime debut = DateTime.Now;
for(int i = 0; i < max; i++)
// j'ajoute mon sample dans la liste
list.Add(sample[i]);
return DateTime.Now - debut;
}
static TimeSpan TestRecherche(IList list, int max)
{
DateTime debut = DateTime.Now;
bool alors;
// recherche (dans l'ordre inverse pour plus de complexité)
for(int i = (max - 1); i >= 0; i--)
// je lit simplement la valeur
alors = list.Contains(i.ToString());
return DateTime.Now - debut;
}
static TimeSpan TestSuppr(IList list, int max)
{
DateTime debut = DateTime.Now;
// supression, ni au début, ni à la fin
while(list.Count > 5000)
list.RemoveAt(5000);
return DateTime.Now - debut;
}
static TimeSpan TestAjout(Hashtable list, int max, object[]sample)
{
DateTime debut = DateTime.Now;
for(int i = 0; i < max; i++)
// j'ajoute mon sample dans la liste
list.Add(i, sample[i]);
return DateTime.Now - debut;
}
static TimeSpan TestRecherche(Hashtable list, int max)
{
DateTime debut = DateTime.Now;
bool alors;
// recherche (dans l'ordre inverse pour plus de complexité)
for(int i = (max - 1); i >= 0; i--)
// je lit simplement la valeur
alors = list.ContainsKey(i);
return DateTime.Now - debut;
}
static TimeSpan TestSuppr(Hashtable list, int max)
{
DateTime debut = DateTime.Now;
// supression, ni au début, ni à la fin
for(int i = 5000; i < max; i++)
// je supprime la valeur identifiée par la chaine qu'elle représente
list.Remove(i);
return DateTime.Now - debut;
} |
Partager