Guest User

Tom

a guest
Apr 15th, 2009
1,433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace ConsoleApplication1
  6. {
  7.     class Program
  8.     {
  9.         public static char Chr(byte src)
  10.         {
  11.             return (System.Text.Encoding.GetEncoding("iso-8859-1").GetChars(new byte[] { src })[0]);
  12.         }
  13.         static void Main(string[] args)
  14.         {
  15.             Dictionary<String,String> nDic = new Dictionary<String,String>();
  16.             int i;
  17.             int x;
  18.             Random rnd = new Random();
  19.             Int64 tTimer = DateTime.Now.Ticks;
  20.             for (i = 1; i <= 1000000; i++)
  21.             {
  22.  
  23.                 // Generate a random UUID
  24.                 String pUUID="";
  25.                 for (x = 1; x <= 16; x++)
  26.                 {
  27.                     pUUID += Chr((byte)rnd.Next(0, 255));
  28.  
  29.                 }
  30.  
  31.                 //Check if pUUID exists in the dictionary
  32.                 if (!nDic.ContainsKey(pUUID))
  33.                 {
  34.                     //If not, add it to the dictionary
  35.                     nDic.Add(pUUID, pUUID);
  36.                 }
  37.  
  38.  
  39.             }
  40.  
  41.             tTimer = DateTime.Now.Ticks - tTimer; //Stop the clock!
  42.             Console.WriteLine("Operation completed in " + ((double)tTimer / (double)TimeSpan.TicksPerSecond).ToString());
  43.             Console.WriteLine(nDic.Count.ToString() + " keys in dictionary");
  44.  
  45.             //Keep the window open at the end of the test
  46.             while (true) ;
  47.  
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment