在C#中调用方法时预热
发布时间:2020-12-15 06:56:19 所属栏目:百科 来源:网络整理
导读:我刚刚遇到了关于时间测量的 this post.我记得(我希望我不会错误的)这是一个不公平的竞争,如果这种方法从来没有被叫过.那是: // At the beginning of the applicationMyClass instance = new MyClass();instance.MyMethod();instance.MyMethod(); // Faster
我刚刚遇到了关于时间测量的
this post.我记得(我希望我不会错误的)这是一个不公平的竞争,如果这种方法从来没有被叫过.那是:
// At the beginning of the application MyClass instance = new MyClass(); instance.MyMethod(); instance.MyMethod(); // Faster than the first call,because now it's warmed up. 我们在C#中真的有这样的热身理论吗?如果是,为什么(CLR做什么热身)?如果这种方法是一个扩展名(静态的),那么一切都是一样的? 解决方法
如果通过“预热”,你可以参考JIT’ing然后是 – 如果方法从未被调用,那么它将不会被编译,所以第一次运行它可能会更慢.
另请参阅 Does the .NET CLR JIT compile every method,every time? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |