tic, toc, apear to be reporting incorrect times when called in App Designer button callback

4 Ansichten (letzte 30 Tage)
I am using App Designer to build an app that, among other things, imports a .csv after pressing an "import" button.
The callback function for this import button includes only about 80 lines of code, but by my estimates takes approximately 30sec-1.5 min. I placed the "tic" function at the beginning of the callback function, and the "toc" function at the end. I also have an edit text field that reads out the current status of the import callback. Using the status edit field as reference, i can tell how long the callback function is "Processing...". My issue is that when the toc value is returned to the workspace and my EditField value, it is calculating the stop watch time as approximately 1.5 seconds, when it is more like 1 min. For example, my code follows the format below.
function ImportButtonPushed(app, event)
tic
app.EditField.Value = 'Processing';
%80-90 lines of code
toc
app.EditField.Value = sprintf('Completed: Processing Time = %f', toc)
end
Has anyone experience similar issues before? Or am I making a simple mistake?
  2 Kommentare
Adam
Adam am 1 Aug. 2019
I tend to use the profiler rather than tic toc when I want to examine multiple lines of code, especially involving builtin functions and implicitly called ones, e.g. you will often find drawnow takinga lot of time where a GUI is concerned. I've often found java GUI component rendering to be quite slow, though I often use the GUI Layout Toolbox and one of the flaws of the layouts is their effect on speed and calls to drawnow.
Walter Roberson
Walter Roberson am 1 Aug. 2019
Unfortunately the profiler tends to disable JIT, and so can give very different timings than production code.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 1 Aug. 2019
Try specifying the output variable:
t = tic();
...
toc(t)
Or record the time yourself:
tstart = now();
...
now()-tstart
(multiply by 24*60*60 to get seconds)
  4 Kommentare
AdamG2013468
AdamG2013468 am 1 Aug. 2019
Per usual, a cursory Google search has revealed a partial answer.
I increased the Java Heap Memory size from the default 768 MB to a larger value, which aided in reducing the processing time. However, i am still seeing times in excess of 90-100 seconds for the single sprintf line.
AdamG2013468
AdamG2013468 am 1 Aug. 2019
Changing the Java Heap Memory size helps some. The wait times for the EditText field and other graphics objects such as a list box to update is what is taking a long time. Using toc throughout the callback indicates that the script itself is being processed rather quickly (1.5-2 seconds), but for the actual app UI to update its graphics takes around 80-100 seconds.
Is their a solution to this, or is this a natural consequence of MATLAB/Java limitations?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Historical Contests finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by