This is a duplicate of Regex slow on Windows Server 2008, but since the accepted answer is not an actual answer, but a workaround, I'm re-asking the question.
The following code:
var complex = @"^(([^<>()[\]\\.,;:\s@""]+"
+ @"(\.[^<>()[\]\\.,;:\s@""]+)*)|("".+""))@"
+ @"((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
+ @"\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+"
+ @"[a-zA-Z]{2,}))$";
var x = Stopwatch.StartNew();
var b = false;
for (var i = 0; i < 1000; i++)
{
Regex r = new Regex(complex, RegexOptions.Compiled | RegexOptions.IgnoreCase);
b = b || r.IsMatch("abc");
}
Console.WriteLine((Environment.Is64BitProcess ? "64-bit: " : "32-bit: ") + x.ElapsedMilliseconds);
runs in:
- 5 seconds when run in 32-bit on my desktop
- 13 seconds when run in 64-bit on my desktop
- 5 seconds when run in 32-bit on my windows 2008 r2 server
- 130 seconds !? when run in 64-bit on my windows 2008 r2 server
This is using .net 4.5.1 on both the desktop and windows 2008 r2 server. This makes no sense to me. What in the world can cause such a slow down on the windows 2008 server? And how can I make it run as fast as my desktop in 64-bit.