How can I calculate CPU time when running the model in simulink???
S-Function Level 1 vs S-Function Level 2
44 views (last 30 days)
I have a problem. I have modeled a dynamic system( 5 inputs and 10 outputs) using S-Function Level-1 and Level-2. Both models work very well. My question is: Why the model that uses S-Function Level-2 runs its simulation very slowly? With the level 1 model simulation is very fast.
Kaustubha Govind on 22 Mar 2012
I don't have a definite answer, and it's difficult to say not having seen your code, but it could be because Level-2 S-functions have a lot more features than Level-1 S-functions, so there is probably a lot of heavy-lifting/back-end work done by them? Exactly how slow are we talking about? Can you provide a ratio?
Profile your code but ticking the 'profile' entry in the Simulink tools menu.
You will probably see that the Level-2 function has its state functions called several thousand times more often than the Level-1 one does (for example my Level-1 function has its output function called ~6000 times, the Level-2 output function is called ~450,000 times!). This is the source of the slow-down, but I don't know how to fix it, sorry. Trying to work that out myself now!