Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disassemble c# code to machine instructions

I am experimenting with compiler performance. I have a very small piece of code, just a few floating point multiplications and 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();
like image 426
danatel Avatar asked May 14 '11 11:05

danatel


3 Answers

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.

like image 188
Guffa Avatar answered Sep 17 '22 22:09

Guffa


Ngen your program and disassemble the results.

like image 29
Andrew Savinykh Avatar answered Sep 20 '22 22:09

Andrew Savinykh


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

like image 45
M4N Avatar answered Sep 17 '22 22:09

M4N