
Tom
By: a guest on Apr 15th, 2009 | syntax:
C# | size: 1.45 KB | hits: 184 | expires: Never
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public static char Chr(byte src)
{
return (System.Text.
Encoding.
GetEncoding("iso-8859-1").
GetChars(new byte[] { src
})[0
]);
}
static void Main(string[] args)
{
Dictionary
<String,
String> nDic
= new Dictionary
<String,
String>();
int i;
int x;
Random rnd
= new Random
();
Int64 tTimer = DateTime.Now.Ticks;
for (i = 1; i <= 1000000; i++)
{
// Generate a random UUID
String pUUID="";
for (x = 1; x <= 16; x++)
{
pUUID += Chr((byte)rnd.Next(0, 255));
}
//Check if pUUID exists in the dictionary
if (!nDic.ContainsKey(pUUID))
{
//If not, add it to the dictionary
nDic.Add(pUUID, pUUID);
}
}
tTimer = DateTime.Now.Ticks - tTimer; //Stop the clock!
Console.WriteLine("Operation completed in " + ((double)tTimer / (double)TimeSpan.TicksPerSecond).ToString());
Console.WriteLine(nDic.Count.ToString() + " keys in dictionary");
//Keep the window open at the end of the test
while (true) ;
}
}
}