tic, toc, apear to be reporting incorrect times when called in App Designer button callback
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
Adam
2019-8-1
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
2019-8-1
Unfortunately the profiler tends to disable JIT, and so can give very different timings than production code.
采纳的回答
Stephen23
2019-8-1
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)
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!