03-13-2023 02:38 AM
Hi,
I have small section of code behind a View area dialogue button, some of which seems to be taking an age to run. I've tracked it down to the Calculate function, of which there are two instances, each taking 1.3-1.4 seconds to run. I wondered if it was the number of data points in the channels, but the second instance is working on channels that are a fraction of the length of the first instance and yet it is always the slowest of the two calls.
The code is as follows with the typical run time in the comment afterwards:
R3 = ApprAnsatzCoef(1) ' 0.004 s
Call Calculate("Ch(""[1]/" & Ychan & """) = Ch(""[1]/" & Ychan & """) - R3") ' 1.33 s
Call Calculate("Ch(""CurveFit/" & Ychan & "_C"") = Ch(""CurveFit/" & Ychan & "_C"") - R3") ' 1.38 s
Call ChnDifferentiate("CurveFit/X Data", "CurveFit/" & Ychan & "_C", "Working/DX Data", "Working/d" & Ychan & "_dLat") ' 0.09 s
Is there something I can do to improved my code to speed it up, or am I stuck with a slow function?
Regards,
Simon.
Solved! Go to Solution.
03-14-2023 05:55 AM
Hi Simon,
Built-in functions are always much faster than the same calculation defined in CALCULATE. This one will be faster:
dim oChnY
set oChnY = Data.GetChannel("[1]/" & Ychan)
ChnLinScale(oChnY, oChnY, 1, R3)
Greetings
Walter
03-14-2023 08:51 PM
Thanks Walter.
05-15-2023 03:00 AM - edited 05-15-2023 03:02 AM
Good morning,
I've got a VBS script that uses the 4 Calculate functions with sines and cosines.
The input channels are sampled at 2048 Hz, hence the calculation is very slow.
Any tips to make it faster?
Considering going through arrays with a GetValueBlock, then a for loop for each index, and finally store the result back in a channel. Not great, code not very readable, but if it's faster, I take it.
Currently using DIAdem 2018, but we should be evaluating DIAdem 2023 in the near future.
Another potential mid-to-long term attempt would be to convert our scripts in Python. Maybe with numpy arrays we could make all that much faster?
Thank you,
Jacques
' Project the rotating moments in the fixed axis
' Upper section
Call Calculate("ch(""63 - Main Rotor Drive/MRSH_MMT_OUT_UPP_MX_CALC"")=ch(""63 - Main Rotor Drive/MRSH_MMT_OUT_UPP_MXY_A"")*cos(rad(ch(""Angular Positions/MRSH_ANG_AZI_OUT_MXY_CALC"")))+ch(""63 - Main Rotor Drive/MRSH_MMT_OUT_UPP_MYX_A"")*cos(rad(ch(""Angular Positions/MRSH_ANG_AZI_OUT_MYX_CALC"")))")
Call Calculate("ch(""63 - Main Rotor Drive/MRSH_MMT_OUT_UPP_MY_CALC"")=-ch(""63 - Main Rotor Drive/MRSH_MMT_OUT_UPP_MXY_A"")*sin(rad(ch(""Angular Positions/MRSH_ANG_AZI_OUT_MXY_CALC"")))-ch(""63 - Main Rotor Drive/MRSH_MMT_OUT_UPP_MYX_A"")*sin(rad(ch(""Angular Positions/MRSH_ANG_AZI_OUT_MYX_CALC"")))")
'Lower section
Call Calculate("ch(""63 - Main Rotor Drive/MRSH_MMT_OUT_LOW_MX_CALC"")=ch(""63 - Main Rotor Drive/MRSH_MMT_OUT_LOW_MXY_A"")*cos(rad(ch(""Angular Positions/MRSH_ANG_AZI_OUT_MXY_CALC"")))+ch(""63 - Main Rotor Drive/MRSH_MMT_OUT_LOW_MYX_A"")*cos(rad(ch(""Angular Positions/MRSH_ANG_AZI_OUT_MYX_CALC"")))")
Call Calculate("ch(""63 - Main Rotor Drive/MRSH_MMT_OUT_LOW_MY_CALC"")=-ch(""63 - Main Rotor Drive/MRSH_MMT_OUT_LOW_MXY_A"")*sin(rad(ch(""Angular Positions/MRSH_ANG_AZI_OUT_MXY_CALC"")))-ch(""63 - Main Rotor Drive/MRSH_MMT_OUT_LOW_MYX_A"")*sin(rad(ch(""Angular Positions/MRSH_ANG_AZI_OUT_MYX_CALC"")))")
05-15-2023 03:16 AM
Hello Jacques,
Rather than add your new question to the end of this one I think it is best practice to create a new post. You will be more likely to receive a response from the folk that can help you.
Regards,
Simon.