I am using a function to plot a somewhat complicated figure with many subplots and lots of data.
I noticed that there was a bit of a lag developing with my function due to the complexity of the figure and I wanted to investigate where the lag is occurring. When I added tic/toc to my function evaluation, I noticed that the output from tic/toc suggests that the script runs in about 0.5 seconds, but there is probably a 1 to 1.5 second lag between the tic/toc output appearing in the Command Window and the figure actually appearing on my screen.
Here is a very simple example which replicates my problem:
for i = 1:6
x = randn(1000000,1);
y = randn(size(x));
In this example, the Command Window outputs around 0.3 seconds of elapsed time using tic/toc. But there is a noticeable lag of probably about 1 second (or even 2 seconds!) on my computer before the figure actually appears.
Why doesn't MATLAB's tic/toc account for this time? What's happening inside MATLAB (or outside of it) to cause this lag?
When I look at my system performance there is negligible impact on CPU or Memory, with only a small increase in GPU usage. I feel like my system should be able to handle much more complicated graphics without lagging.
Any info is appreciated.
Specs: I am using MATLAB 2020a running on Windows 10 (1909). Intel i7-3930K CPU @ 3.2GHz. 32 GB RAM and NVIDIA GeForce GT 520 GPU.