您的位置:首页 > 其它

foreach与for的性能比较

2012-05-02 22:14 337 查看
1
string
[] strings=
new

string
[] {
"str1"
,
"str2"
,
"str3"
,
"str4"
,
"str5"
,
"str6"

};

2
foreach

(
string

s
in

strings)

3
{

4
    
textBox1.AppendText(s+
" "
);

5
}


IL:

01
foreach

(
string

s
in

strings)

02
000000e0  nop


03
000000e1  mov         eax,dword ptr [ebp-44h]

04
000000e4  mov         dword ptr [ebp-50h],eax

05
000000e7  xor         edx,edx

06
000000e9  mov         dword ptr [ebp-54h],edx

07
000000ec  nop


08
000000ed  jmp         00000136
//jmp to J1

09
000000ef  mov         eax,dword ptr [ebp-54h]

10
000000f2  mov         edx,dword ptr [ebp-50h]

11
000000f5  cmp         eax,dword ptr [edx+4]

12
000000f8  jb          000000FF         
//低于"1个字节全是1"跳转

13
000000fa  call        65C86690         
//地址如此之大,应该是个外部call

14
000000ff  mov         eax,dword ptr [edx+eax*4+0Ch]

15
00000103  mov         dword ptr [ebp-48h],eax

16
{

17
00000106  nop


18
    
textBox1.AppendText(s+
" "
); </COD < dd>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: