有人能解释一下吗? [英] Can anyone explain this please ?

查看:88
本文介绍了有人能解释一下吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个循环,使用一个名为isLyingInCone的子程序分析一系列数字,一切正常,除了速度。



该应用大约需要4个小时(这是预期的,它会通过大量数据来实现)以便运行,因此缩短流程是值得的。我正在尝试一点一点地做这件事,我确信其他地方有很多工作要做,但我发现一个主要的罪魁祸首是以下IF声明,我无法理解为什么下面的行应该将分析时间从大约4倍增加到8小时。请问有什么想法吗?





I have a loop that analyses a series of numbers using a sub routine called isLyingInCone and everything is working OK except the speed.

The app takes about 4 hours (that's expected, it crunches through a lot of data) to run and so shortening processes is worthwhile. I'm trying to do this bit by bit and I'm sure there is much to do elsewhere, but I discovered a main culprit was the following IF statement and I cannot understand why the lines below should DOUBLE the analysis time from about 4 to 8 hours. Any idea please?


Dim XTRange As Double
Dim NearAngle As Double
Dim FarAngle As Double
Dim myAngle As Double

If XTRange < 500 Then myAngle = NearAngle Else myAngle = FarAngle 'using this doubles the time ! A select Case instead made little difference

'myAngle = FarAngle 
'If I uncomment the line above it speeds up again - even when leaving the above IF line intact.

If isLyingInCone(Xx, Xy, Xz, Tx, Ty, Tz, Bx, By, Bz, myAngle) = True Then
'here we do the maths
End if





有什么帮助吗?我感到很困惑,因为我认为IF语句无论如何都会运行。只需添加



Any help? Im baffled as I'd have thought the IF statement would run anyhow. The difference in time in just adding the

myAngle = FarAngle

行的时间差异就在4到8小时之间。



谢谢

line is enormous at 4 - 8 hrs

Thanks

推荐答案

您提供的代码没有解决方案。

myAngle 是什么是吃饭时间的参数,所以你的代码没有兴趣。

你需要在 profiler 上运行你的代码,只需要一小部分数据;

探查器会告诉你程序在哪里花费时间。您可能会看到一小段线或一个函数一直在吃东西。

这个函数是您需要列出的几个示例参数,然后就可以理解了为什么它如此长,如果有可能优化你的代码。



这种任务通常由专业程序员执行,并具有完整的项目源代码和足够的数据看看有什么附加。

所有都需要,因为这是一个迭代过程。

Profiler>看时间吃饭>调整> profiler>看到差异>再次调整...



程序员需要完全理解代码中的有罪部分才能优化它并且非常有效。
There is no solution with the code you provided.
myAngle is a parameter to what is eating time, so your code have no interest.
You need to run your code on profiler with a small sample of data;
The profiler will tell you where your program is spending time. You will probably see that a small set of lines or a function is eating all the time.
This function is what you need to list with a couple of example parameters, and then it will be possible to understand why it is so long and if it is possible to optimise your code.

This kind of task is usually performed by professional programmer and with full project source code and enough data to see what append.
All is needed because this is an iterative process.
Profiler > see time eater > tweak > profiler > see differences > tweak again ...

The programmer need to fully understand the guilty part of your code in order to optimise it and be really efficient.

这篇关于有人能解释一下吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆