热身调用C#方法时,方法

由网友((り指尖燦爛了誰旳傷っ)分享简介:刚刚遇到以this帖子大约时间测量的会谈,我记得(希望我没有记错),这是一个不公平的竞争,如果这种方法不会被调用之前。那就是:Just come across to this post that talks about time measuring, I remember(hope I'm not misrememb...

刚刚遇到以this帖子大约时间测量的会谈,我记得(希望我没有记错),这是一个不公平的竞争,如果这种方法不会被调用之前。那就是:

Just come across to this post that talks about time measuring, I remember(hope I'm not misremembering) it's an unfair competition, if this method is never called before. That is:

//at the beginning of the app
MyClass instance = new MyClass();
instance.MyMethod();  
instance.MyMethod();  // faster than the first call, because now it's warmed up.

难道我们真的有这样的热身理论在C#中?如果是的话,为什么(会出现什么CLR做准备活动时)?而就是一切相同的,如果这个方法是一个扩展一(静态的)?

Do we really have such warming-up theory in C#? If yes, why(what will the CLR do when warming-up)? And is everything the same if this method is an extension one(a static one)?

推荐答案

如果通过热身你是指JIT'ing然后是 - 如果一个方法不会被调用也不会被编译呢,所以很第一次运行时,可能会比较慢。 另请参阅Does在.NET CLR JIT编译每个方法,每一次?

If by "warm up" you refer to JIT'ing then yes - if a method is never called it won't have been compiled yet, so the very first time you run it it might be slower. Also refer to Does the .Net CLR JIT compile every method, every time?

阅读全文

相关推荐

最新文章