在C#中调用方法时预热

在C#中调用方法时预热,第1张

概述我刚刚遇到了关于时间测量的 this post.我记得(我希望我不会错误的)这是一个不公平的竞争,如果这种方法从来没有被叫过.那是: // At the beginning of the applicationMyClass instance = new MyClass();instance.MyMethod();instance.MyMethod(); // Faster than th 我刚刚遇到了关于时间测量的 this post.我记得(我希望我不会错误的)这是一个不公平的竞争,如果这种方法从来没有被叫过.那是:
// At the beginning of the applicationMyClass 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? 总结

以上是内存溢出为你收集整理的在C#中调用方法时预热全部内容,希望文章能够帮你解决在C#中调用方法时预热所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1260334.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存