将 int 替换为 double 时的 Visual Studio 长编译 [英] Visual studio long compilation when replacing int with double

查看:20
本文介绍了将 int 替换为 double 时的 Visual Studio 长编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 VS2013 Ultimate 副本编译此代码超过 60 秒:

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;
    }
}

但是如果我用 int 替换 double,它会立即编译.怎么解释...?

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

推荐答案

我在我的机器上重现,27 秒.作恶者是MsMpEng.exe,它会在那么长时间内燃烧100%的核心.在任务管理器的进程选项卡中很容易看到.

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.

这是 Windows Defender 服务,实际执行恶意软件扫描的服务.通过取消选中打开实时保护"选项来禁用它会立即修复延迟.将我存储项目的路径添加到排除的文件位置"框中也是如此,这可能是您的首选方法.

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.

我不想猜测根本原因,但必须假设您的源代码正在触发恶意软件规则.不是一个很好的解释,当我针对 .NET 版本时我没有看到延迟 <4.0.好吧,我放弃了:)

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 :)

这篇关于将 int 替换为 double 时的 Visual Studio 长编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆