public
Created

C sharp vs real basic

  • Download Gist
CSharpBenchmark
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
//taking in thomasz suggestions
//https://pay.reddit.com/r/programming/comments/zm0gc/clash_of_the_unlikely_c_versus_realbasic/c65sksv
 
static void Main(string[] args)
{
Dictionary<String, String> nDic = new Dictionary<String, String>();
int i;
var enc = Encoding.GetEncoding("iso-8859-1");
Random rnd = new Random();
Int64 tTimer = DateTime.Now.Ticks;
for (i = 1; i <= 1000000; i++)
{
var pUUIDBytes = new byte[16];
 
// Generate a random UUID
rnd.NextBytes(pUUIDBytes);
 
var pUUID = enc.GetString(pUUIDBytes);
 
//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() + " seconds");
Console.WriteLine(nDic.Count.ToString() + " keys in dictionary");
 
//Keep the window open at the end of the test
Console.Read();
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.