Skip to content

@Romoku /CSharpBenchmark
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
C sharp vs real basic
//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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.