I'm writing a data structure and if I set <gcServer enabled="true" />
in my app.config
file, the program adds 500,000 items in 200 milliseconds. If I set <gcServer enabled="false" />
it takes 300 milliseconds. That is, setting this flag to false makes it take 50% longer consistently, as measured by a Stopwatch
.
I'm wondering why this is because I am not doing any garbage collecting. I know it is done automatically sometimes but after profiling with CLRProfiler, I can confirm 0 collections are occurring:
Does anyone know why this is happening? If the garbage collector isn't even running, then why is a server garbage collector so much faster? Here is the code where I am checking the speed differences:
Stopwatch sw = Stopwatch.StartNew();
foreach (string s in items)
{
dataStructure.Add(s, s + "a");
}
sw.Stop();