我正在尝试了解分析器报告并使用它来优化我的代码。我遇到的问题是我没有看到突出显示案例软件的任何问题!
例如:
14.2% public int vbar.X {get{return vbar.x;} set {vbar.x = value;}}
// time
for (int t = 2; t < 1000000; t++)
{
// main calculations
for (int i = 2; i < 800; i++)
{
0.5% for (int j = 2; j < 800; j++)
{
vbar.X = 0.0;
34% vbar.Y = 0.0;
// some culculations for vbar.X and vbar.Y
lap.X = ((((theSpace.TheCells[i + 1, j, 0].Velocity.X - theSpace.TheCells[i, j, 0].Velocity.X) / theSpace.TheCells[i + 1, j, 0].Nondx) - ((theSpace.TheCells[i, j, 0].Velocity.X - theSpace.TheCells[i - 1, j, 0].Velocity.X) / theSpace.TheCells[i, j, 0].Nondx)) * (2 / (theSpace.TheCells[i + 1, j, 0].Nondx + theSpace.TheCells[i, j, 0].Nondx)))
+ (((theSpace.TheCells[i, j + 1, 0].Velocity.X - theSpace.TheCells[i, j, 0].Velocity.X) / theSpace.TheCells[i, j + 1, 0].Nondy) - ((theSpace.TheCells[i, j, 0].Velocity.X - theSpace.TheCells[i, j - 1, 0].Velocity.X) / theSpace.TheCells[i, j, 0].Nondy)) * (2 / (theSpace.TheCells[i, j + 1, 0].Nondy + theSpace.TheCells[i, j, 0].Nondy));
vbar.X = theSpace.TheCells[i, j, 0].Velocity.X - theSpace.Dt * (adv.X - Math.Sqrt(slnParameter.Pr / slnParameter.Ra) * lap.X);
lap.Y = ((((theSpace.TheCells[i + 1, j, 0].Velocity.Y - theSpace.TheCells[i, j, 0].Velocity.Y) / theSpace.TheCells[i + 1, j, 0].Nondx) - ((theSpace.TheCells[i, j, 0].Velocity.Y - theSpace.TheCells[i - 1, j, 0].Velocity.Y) / theSpace.TheCells[i, j, 0].Nondx)) * (2 / (theSpace.TheCells[i + 1, j, 0].Nondx + theSpace.TheCells[i, j, 0].Nondx)))
+ (((theSpace.TheCells[i, j + 1, 0].Velocity.Y - theSpace.TheCells[i, j, 0].Velocity.Y) / theSpace.TheCells[i, j + 1, 0].Nondy) - ((theSpace.TheCells[i, j, 0].Velocity.Y - theSpace.TheCells[i, j - 1, 0].Velocity.Y) / theSpace.TheCells[i, j, 0].Nondy)) * (2 / (theSpace.TheCells[i, j + 1, 0].Nondy + theSpace.TheCells[i, j, 0].Nondy));
vbar.Y = theSpace.TheCells[i, j, 0].Velocity.Y - theSpace.Dt * (adv.Y - Math.Sqrt(slnParameter.Pr / slnParameter.Ra) * lap.Y - theSpace.TheCells[i, j, 0].Temperature);
}
}
}
...
根据此示例,我的代码有以下几行问题:
所有这些变量都是整数:
vbar.X = 0.0
,int j = 2
和j++
。正如你在第二张图片中看到的那样。
我该如何解决这些问题?或者这些循环的哪个部分有问题?
对包含39%包含时间的代码(vbar.X = 0.0
)进行编码的另一种方法是什么?
有趣的是,通过分析器获取结果所需的时间是代码运行所需的时间的一半!
/////////////////////////////////////////////// ////////////////////////////////////////////////// /////
我找到了部分问题的答案。
关于这部分(vbar.X = 0.0
),这是不正确的,因为我可以把它放在我的循环的一边,避免在每次迭代中重复它。
/////////////////////////////////////////////// ////////////////////////////////////////////////// /////
答案 0 :(得分:1)
这可能是源代码行突出显示分析器功能的不准确现象。如果可能的话,我会在Visual Studio "14" preview中尝试一下,看看它是否已修复,因为我们最近在这方面做了一些改进。
也就是说,在发布模式下,源代码映射由于可能发生的优化而不是100%准确,特别是对于.NET代码。作为一般规则,如果突出显示的行不同意调用树视图所说的内容,则支持调用树。