小编utr*_*rbc的帖子

两条相似行的CPU时间差异

有一个在我的节目,其中一个while循环IterZNext,IterZ是指向列表中的节点.列表中的节点是struct类型,带有一个名为"Index"的字段.

double xx = 20.0;
double yy = 10000.0;
double zz;      
while (IterZNext!=NULL && NextIndex<=NewIndex)
{
    IterZ=IterZNext;
    IterZNext = IterZ->Next;
    if (IterZNext!=NULL)
    {
        zz = xx + yy;
                NextIndex1 = IterZNext->Index; // line (*)
        NextIndex = IterZNext->Index;  // line (**)
        IterZNext->Index;
    }
}
Run Code Online (Sandbox Code Playgroud)

当我描述我的程序时,我找到了行(*)

NextIndex1 = IterZNext->Index;
Run Code Online (Sandbox Code Playgroud)

消耗大部分CPU时间(2.193s),而行(**)

NextIndex = IterZNext->Index;
Run Code Online (Sandbox Code Playgroud)

与行(*)最相似的只使用0.093s.我使用英特尔VTune放大器来查看这两条线的组装,如下所示:

Address Line    Assembly                   CPU Time Instructions Retired
Line (*):
0x1666  561 mov eax, dword ptr [ebp-0x44]   0.015s  50,000,000
0x1669  561 mov ecx, dword ptr …
Run Code Online (Sandbox Code Playgroud)

c c++ assembly profiling cpu-usage

5
推荐指数
2
解决办法
246
查看次数

标签 统计

assembly ×1

c ×1

c++ ×1

cpu-usage ×1

profiling ×1