OK, momma said not to feed the trolls, but I was curious.
This is a silly benchmark, since it is basically calculating n^6. The C++ and C++/CLI compiler figures this out, but the
C# compiler doesn't. Interestingly, neither does the JITer. Everything was compiled with optimizations on under VS2005.
The loop:
for (a=0; a<n; a++)
for (b=0; b<n; b++)
for (c=0; c<n; c++)
for (d=0; d<n; d++)
for (e=0; e<n; e++)
for (f=0; f<n; f++)
x++;
C++ assembly:
00401025 mov ecx,eax
00401027 imul ecx,eax
0040102A imul ecx,eax
0040102D imul ecx,eax
00401030 imul ecx,eax
00401033 imul ecx,eax
C++/CLI IL:
L_000f: ldloc.0
L_0010: dup
L_0011: mul
L_0012: ldloc.0
L_0013: mul
L_0014: ldloc.0
L_0015: mul
L_0016: ldloc.0
L_0017: mul
L_0018: ldloc.0
L_0019: mul
C++/CLI JITed:
00000046 mov edi,esi
00000048 mov eax,esi
0000004a mov edx,esi
0000004c mov ecx,esi
0000004e mov ebx,esi
00000050 imul ebx,esi
00000053 imul ecx,ebx
00000056 imul edx,ecx
00000059 imul eax,edx
0000005c imul edi,eax
C# IL:
L_0000: ldc.i4.0
L_0001: stloc.s num7
L_0003: ldc.i4.0
L_0004: stloc.0
L_0005: br.s L_0055
L_0007: ldc.i4.0
L_0008: stloc.1
L_0009: br.s L_004d
L_000b: ldc.i4.0
L_000c: stloc.2
L_000d: br.s L_0045
L_000f: ldc.i4.0
L_0010: stloc.3
L_0011: br.s L_003d
L_0013: ldc.i4.0
L_0014: stloc.s num5
L_0016: br.s L_0034
L_0018: ldc.i4.0
L_0019: stloc.s num6
L_001b: br.s L_0029
L_001d: ldloc.s num7
L_001f: ldc.i4.1
L_0020: add
L_0021: stloc.s num7
L_0023: ldloc.s num6
L_0025: ldc.i4.1
L_0026: add
L_0027: stloc.s num6
L_0029: ldloc.s num6
L_002b: ldarg.0
L_002c: blt.s L_001d
L_002e: ldloc.s num5
L_0030: ldc.i4.1
L_0031: add
L_0032: stloc.s num5
L_0034: ldloc.s num5
L_0036: ldarg.0
L_0037: blt.s L_0018
L_0039: ldloc.3
L_003a: ldc.i4.1
L_003b: add
L_003c: stloc.3
L_003d: ldloc.3
L_003e: ldarg.0
L_003f: blt.s L_0013
L_0041: ldloc.2
L_0042: ldc.i4.1
L_0043: add
L_0044: stloc.2
L_0045: ldloc.2
L_0046: ldarg.0
L_0047: blt.s L_000f
L_0049: ldloc.1
L_004a: ldc.i4.1
L_004b: add
L_004c: stloc.1
L_004d: ldloc.1
L_004e: ldarg.0
L_004f: blt.s L_000b
L_0051: ldloc.0
L_0052: ldc.i4.1
L_0053: add
L_0054: stloc.0
L_0055: ldloc.0
L_0056: ldarg.0
L_0057: blt.s L_0007
C# JITed:
0000003e xor edx,edx
00000040 mov dword ptr [esp],edx
00000043 nop
00000044 jmp 0000009A
00000046 xor edx,edx
00000048 mov dword ptr [esp+4],edx
0000004c nop
0000004d jmp 00000091
0000004f xor ebx,ebx
00000051 nop
00000052 jmp 00000089
00000054 xor edx,edx
00000056 mov dword ptr [esp+8],edx
0000005a nop
0000005b jmp 00000082
0000005d xor edx,edx
0000005f mov dword ptr [esp+0Ch],edx
00000063 nop
00000064 jmp 00000078
00000066 xor ebp,ebp
00000068 nop
00000069 jmp 00000070
0000006b inc dword ptr [esp+10h]
0000006f inc ebp
00000070 cmp ebp,esi
00000072 jl 0000006B
00000074 inc dword ptr [esp+0Ch]
00000078 cmp dword ptr [esp+0Ch],esi
0000007c jl 00000066
0000007e inc dword ptr [esp+8]
00000082 cmp dword ptr [esp+8],esi
00000086 jl 0000005D
00000088 inc ebx
00000089 cmp ebx,esi
0000008b jl 00000054
0000008d inc dword ptr [esp+4]
00000091 cmp dword ptr [esp+4],esi
00000095 jl 0000004F
00000097 inc dword ptr [esp]
0000009a cmp dword ptr [esp],esi
0000009d jl 00000046