Story : How to run script faster
You can increase the speed of calculation by the following syntax which ensures that only array values are furter used, unlike complete formulas defining the values, like in standard cases:
Fcs.Types.Array(array).ItemValues
I was wondering, many times, if there is a difference in decision which variant is used made by ternary operators or picking an item from an array. In case there are more than just two variants (let's take 4 in this case) the syntax of ternary operator becomes quote complicated:
value := (variant == 0)?(varA):((variant == 1)?(varB):((variant == 2.........)))
A bit more comprehensive is the array "picker":
value := [varA, varB, varC, varD][variant]
But there is a danger that each of the array items is time consuming and because whole array is evaluated first and particular variant is used further afterwards, this may be too "expensive". Also, there might be a situation when some of the array item is even not evaluable. In this our code fails.
Thanks God (and our FemCad guru), we have one more option which is both fast enough and easy to read. An array of lambdas. The above examples could go like this:
varArray := [(i => varA), (i => varB), (i => varC), (i => varD)]
value := varArray[variant](0)
- Localisation
- Basics
- FemCAD workings
- Geometry
- Input
- Direct edit
- Analysis
- Output
-
Stories
- FAQ
- Stupid user mistakes
- How to discover speed issues in the code
- How to run script faster
- How to list evaluated variables
- How I got lost in graphical interface when dealing with labels
- How to create Bill of material
- How to deal with point transfer between UCS and LCS
- How to define input
- How to make output