tags:

views:

73

answers:

3

As far I recall the function is JIT'd when it is called second time.

What about the Main method? Would the code inside be JIT'd?

If I mesure some chunk of code, should I wrapped it in a function?

+1  A: 

A method is jitted the first time it is called.

.Net is not capable of executing non-jitted methods.

So the main is jitted.

See also this answer from Jon Skeet.

GvS
+6  A: 

All .NET (MSIL) code has to be JIT'ed (compiled to native code) before it can be executed.

You are perhaps referring to the fact that once code has been JIT'ed it is cached. The overhead of JIT'ing is only incurred once. If you want to perform a benchmark without the JIT overhead you will have to "preheat" your benchmark or perhaps use NGEN to compile the MSIL permanently.

Martin Liversage
+3  A: 

To answer the side question:

If I mesure some chunk of code, should I wrapped it in a function?

This is presumably about measuring the performance of some code, where the usual advice is to place it in a method, and call that method at least once, before starting your timing loops. This is so that you avoid the JIT overhead that's normally incurred the first time a method is called.

Damien_The_Unbeliever