I'm using Visual Studio 2012, 64bit Quad Core Windows 7 OS, .Net framework 4.5.2.
Project is a console application running in Release mode; JIT disabled.
In a C++ environment, there is no slow down on the first iteration. In a C# environment there is substantial slow down. It has been suggested in other similar posts that this is due to Jitting. However, after disabling JIT via Tools->Options->Debugging->Just-in-time (and uncheck the JIT checkboxes) - there is no observable speed up. Below is an example that you can try yourself. Can anyone explain to me how to be "fully compiled" prior to executing the application? This is a low iteration process and I need all iterations to execute quickly.
private static void Main(string[] args)
{
int counter = 10;
while (counter != 0)
{
DoArray();
counter--;
}
}
public static void DoArray()
{
var stopwatch = new Stopwatch();
int[] set = {0, 1, 9, 10, 11};
int[] toRemove = {1, 14, 27, 40};
stopwatch.Start();
int[] removed = RemoveElementsFromSet(set, toRemove);
stopwatch.Stop();
if (removed.Length != 4)
throw new ApplicationException("ERROR");
Console.WriteLine("elapsed[ticks]: {0}", stopwatch.ElapsedTicks);
}
internal static int[] RemoveElementsFromSet(int[] set, int[] toRemove)
{
var removed = new int[set.Length];
int removedIndex = 0;
for (int i = 0; i < set.Length; i++)
{
if (toRemove.Contains(i))
continue;
removed[removedIndex] = set[i];
removedIndex++;
}
Array.Resize(ref removed, removedIndex);
return removed;
}
}
elapsed[ticks]: 6651 elapsed[ticks]: 7 elapsed[ticks]: 6 elapsed[ticks]: 6 elapsed[ticks]: 5 elapsed[ticks]: 5 elapsed[ticks]: 6 elapsed[ticks]: 5 elapsed[ticks]: 3 elapsed[ticks]: 2 Press any key to continue . . .