【发布时间】:2009-09-24 20:19:44
【问题描述】:
我有这种 C 函数——被无数次调用:
void foo ()
{
if (/*condition*/)
{
}
else if(/*another_condition*/)
{
}
else if (/*another_condition_2*/)
{
}
/*And so on, I have 4 of them, but we can generalize it*/
else
{
}
}
我有一个很好的测试用例调用这个函数,导致某些 if 分支比其他分支被调用得更多。
我的目标是找出安排 if 语句以最小化分支的最佳方式。
我能想到的唯一方法是为每个分支到的 if 条件写入文件,从而创建直方图。这似乎是一种乏味的方式。有没有更好的方法、更好的工具?
我正在使用 gcc 3.4 在 AS3 Linux 上构建它;使用 oprofile (opcontrol) 进行分析。
【问题讨论】:
-
这是一个令人毛骨悚然的用户名...
标签: c++ c optimization performance