开发者

disassemble c# code to machine instructions

开发者 https://www.devze.com 2023-03-06 09:07 出处:网络
I am experimenting with compiler performance. I have a very small piece of code, just a few floating point multiplications and 开发者_Python百科additions. The code gets executed in a loop several mill

I am experimenting with compiler performance. I have a very small piece of code, just a few floating point multiplications and 开发者_Python百科additions. The code gets executed in a loop several million times. I am trying to compile the code in C++, c#, java, perl, python ... and then I run the result while measuring execution time.

I am quite dissatisfied with c# performance. My c# code is about 60% slower than equivalent C++ or java. I am sure, there must be a bug in my experiment. I would like to disassemble the resulting binary to learn why.

Is there such a option with MSIL code? Can the result of the c# JIT compiler be examined on the machine instruction level (x86 instructions, not MSIL instructions)?

Update

the code (u, v, g* are double; steps is integer)

stopwatch.Start();
for (int i = 0; i < steps; i++)
{
    double uu = g11 * u + g12 * v;
    v = g21 * u + g22 * v;
    u = uu;
}
stopwatch.Stop();


Debug your code in Visual Studio (but compile in release mode), put a breakpoint in the loop, and open the Disassembly window (Debug -> Windows -> Disassembly) when the execution stops at the breakpoint.


Ngen your program and disassemble the results.


Maybe you could ngen (compile to native code) the binary first, to avoid the JIT compilation.

0

精彩评论

暂无评论...
验证码 换一张
取 消