Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My copy of VS2013 Ultimate compiles this code for 60+ seconds:

class Program
{
    static void Main(string[] args)
    {
        double dichotomy = Dichotomy(
            d =>
            {
                try
                {
                    int size = (int) d;
                    byte[] b = new byte[size];
                    return -b.Length;
                }
                catch (Exception)
                {
                    return 0;
                }
            },
            0,
            int.MaxValue,
            1);

        Console.WriteLine(dichotomy);
        Console.ReadKey();
    }

    private static double Dichotomy(
        Func<double, double> func,
        double a,
        double b,
        double epsilon)
    {
        double delta = epsilon / 10;
        while (b - a >= epsilon)
        {
            double middle = (a + b) / 2;
            double lambda = middle - delta, mu = middle + delta;
            if (func(lambda) < func(mu))
                b = mu;
            else
                a = lambda;
        }
        return (a + b) / 2;
    }
}

But if I replace double with int, it compiles immediately. How can be it explained...?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
230 views
Welcome To Ask or Share your Answers For Others

1 Answer

I repro, 27 seconds on my machine. The evil-doer is MsMpEng.exe, it burns 100% core for that long. Easy to see in Task Manager's Processes tab.

This is the Windows Defender service, the one that actually performs the malware scans. Disabling it by unticking the "Turn on real-time protection" option instantly fixes the delay. So does adding the path where I store projects to the "Excluded file locations" box, probably your preferred approach.

I'd hate to have to guess at the underlying reason, but have to assume that your source code is triggering a malware rule. Not a great explanation, I don't see the delay when I target a .NET version < 4.0. Okay, I give up :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...