Thursday, January 28, 2010

Why name JIT?

.net compiler convert source code into intermediate language during compilation. this is also called as Microsoft intermediate language(MSIL).
Its the job of the JIT compiler to take MSIL and convert it to native code at run time.


.net will not convert all MSIL code into native code at once. Because it is time and space consuming. Some part of the .net code never executes. So there is no need to keep this code in the memory. This is resource consuming.


So .net came up with an approach called JIT compilation, it converts MSIL to native code on demand at application runtime. So the name JUST IN TIME COMPILING

Wednesday, January 6, 2010

Measuring execution time in C#

How to measure a method's execution time without using timer?

Use DateTime and TimeSpan classes in .net framework.

public void sampleMethod()
{
DateTime starttime = DateTime.Now;
//
//......
//do code here
//......
DateTime endtime = DateTime.Now;
TimeSpan duration = endtime - starttime;
string time = duration.Hours + ":" + duration.Minutes + ":" + duration.Seconds + ":" + duration.Milliseconds;
}