Story : How to discover speed issues in the code - HiStructClient/femcad-doc GitHub Wiki
Speed measuring in FemCad
There are several key features that users require and that can be the key stone for successful business. One of them is speed of the software we provide. The speed of software tool is controlled by more aspects but one of the is the code script itself. We should avoid unwanted laps where the evaluation of particular variable takes too long or is repeated many times, although there is no need for it. To discover such places the following trick can be used. It does not give any immediate solution - it is just a hint to the developer where to put the focus. And he/she has to re-think the code lines and adapt it if possible. However there are more solutions available...
1. Run FemCad using Profile.bat
Open particular *.fcs file in FemCad that is run via Profile.bat. As soon as the file is opened (immediately) close FemCad application. Report in html browser appears.
2. Analyse expression speed log
The report in html shows total time, number of calls and allocated memory for individual expressions.
You can browse the report and evaluate if there is somewhere particular function that is run much more times than the previous one, or that takes looooong time. The report it ordered from the longest expression to the shortest one.
Encasing part of code by time-measuring function
There is Fcs.Diagnostics.Clock2 function, which enables us to measure part of the code execution. The function has three parameters: 1 - string name wchicch is outputted in every invocation 2 - lambda input 3 - lambda output
Example of the function:
BuildedRockets := res.f.EnumerableRange(10).Select( i => RocketFactoryFn(i) )
RocketFactoryFn := i => Fcs.Diagnostics.Clock2(
"Building rocket number " + i.ToString(),
( none => buildRocketByNumberFn( i ) ),
( output => " output" )
)
buildRocketByNumberFn := i => + "The rocket number " + i.ToString() + " has been built."
Ouptut of the BuildedRockets is then:
[2018/10/10 11:04:51.30] Building rocket number 0 output ...0 s
[2018/10/10 11:04:51.30] Building rocket number 1 output ...0 s
[2018/10/10 11:04:51.30] Building rocket number 2 output ...0 s
[2018/10/10 11:04:51.30] Building rocket number 3 output ...0 s
[2018/10/10 11:04:51.30] Building rocket number 4 output ...0 s
[2018/10/10 11:04:51.30] Building rocket number 5 output ...0 s
[2018/10/10 11:04:51.30] Building rocket number 6 output ...0 s
[2018/10/10 11:04:51.30] Building rocket number 7 output ...0 s
[2018/10/10 11:04:51.30] Building rocket number 8 output ...0 s
[2018/10/10 11:04:51.30] Building rocket number 9 output ...0 s
[2018/10/10 11:04:51.30] [
"The rocket number 0 has been built.",
"The rocket number 1 has been built.",
"The rocket number 2 has been built.",
"The rocket number 3 has been built.",
"The rocket number 4 has been built.",
"The rocket number 5 has been built.",
"The rocket number 6 has been built.",
"The rocket number 7 has been built.",
"The rocket number 8 has been built.",
"The rocket number 9 has been built."
]