tic, toc, apear to be reporting incorrect times when called in App Designer button callback
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
AdamG2013468
am 31 Jul. 2019
Kommentiert: Walter Roberson
am 1 Aug. 2019
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
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
am 1 Aug. 2019
Unfortunately the profiler tends to disable JIT, and so can give very different timings than production code.
Akzeptierte Antwort
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
Weitere Antworten (0)
Siehe auch
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!