Actually not anwer, but too long for a comment ... The problem with the code in the question seems to be related to the performance difference between .NET 2 and 4. In particular, I see DateTime.Now much slower in .NET 4 than in version 2.0.
The result of the test console application below (after several attempts) is about 300, 310 milliseconds for .net 2 and 1050, 1090 milliseconds on .NET 4.
Posting code so that others can try other configuration platforms. I am in Windows 7-64 bits compiling in release mode.
using System; using System.Diagnostics; class Program { public static void Main(string[] args) { const int m = 1000000; DateTime d; Stopwatch s1 = Stopwatch.StartNew(); for (int i = 0; i < m; i++) { d=DateTime.Now; } s1.Stop(); Stopwatch s2 = Stopwatch.StartNew(); for (int i = 0; i < m; i++) { DateTime.Now.AddSeconds(10); } s2.Stop(); Console.WriteLine("{0}, {1}",s1.ElapsedMilliseconds,s2.ElapsedMilliseconds); Console.Read(); } }
source share