NOT A DIRECT RESPONSE (but it is imperative to obtain the necessary support information):
Some of the answers provided are pretty good to directly answer your question. However, to accomplish what you are trying to do, I would like to add a couple of notes.
First, consider the time-consuming just-in-time (jit) compiler that occurs at runtime. Any code where you take the initial timestamp, then do things, and then take the final timestamp to subtract t2-t1 for delta for any function inside the material, if you include any functions that you have not yet called during the current process , then the first time you call it, you will pay for jit overhead to compile the bytecode into native code. In this case, the cost does not reflect the actual cost of the critical performance code at runtime, which is apparently often called the code that is often called, and yet the cost of jit is paid only once (the first time this process is called). So call the time code several times, throw away the first time and take the average.
Also, beware of the time taken to complete the garbage collector. If you're just playing, it may be possible and interesting to compare code that strictly avoids highlighting new objects. But sometimes this is not easy, especially when you call functions whose implementations you cannot change. In addition, I must provide you that the real world overhead of the production code cannot avoid the overhead of garbage collection, so getting a realistic figure should include this overhead. However, if your stuff contains code that allocates new objects, then it can start a garbage collector, which will be expensive, so be prepared for some potential outliers that you might want to throw away.
Secondly, good answers provided code for declaring external functions to be called from system dlls and what was great. The proper use of these signatures in the general case can be a nuisance, so I would like to mention a great resource for this: pinvoke.net. The QueryPerformanceCounter search gave me signatures that cut and cut from the answer already provided, and this is a great resource for any system calls you want to make.
http://pinvoke.net/search.aspx?search=QueryPerformanceCounter&namespace=[All]
source share