热身调用C#方法时, [英] Warm-up when calling methods in C#

查看:102
本文介绍了热身调用C#方法时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚遇到以<一href="http://stackoverflow.com/questions/232848/wrapping-stopwatch-timing-with-a-delegate-or-lambda">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然后是 - 如果一个方法不会被调用也不会被编译呢,所以很第一次运行时,可能会比较慢。 另请参阅<一个href="http://stackoverflow.com/questions/1255803/does-the-net-clr-jit-compile-every-method-every-time">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?

这篇关于热身调用C#方法时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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