My Matlab code (the same one) is running extremely slow on a fairly new and powerful PC and is running fast (10x times faster) on my weaker laptops

35 views (last 30 days)
My Matlab (R2017A) code (the same one) is running extremely slow on a fairly new and powerful PC (AMD Ryzen 7 1700 8core 3Ghz, 16GB Ram) and is running fast (10x times faster) on my older and weaker laptops (dell xps 15 and dell alienware). The code basically uploads and analyze video frames, nothing special. Either I have problems with the hardware or with the Matlab. Please advise on how I can check whether the issue is with Matlab and, if there is one, how to fix it.
  9 Comments
Dyuman Joshi
Dyuman Joshi on 28 Jun 2022
@Rik, can you explain a bit more about how you know this stuff to a noob? Is there any related information given with a version release?

Sign in to comment.

Answers (1)

Rik
Rik on 28 Jun 2022
Edited: Rik on 29 Jun 2022
I started to write this as a comment, but I realized this makes more sense as an answer.
These are the general trends for newer releases:
  1. Increased speed for many function.
  2. Lower speed for some functions (but generally not in the long run).
  3. Slower startup of Matlab.
  4. More RAM required.
  5. More features related to debugging and meta-programming (unit testing etc).
  6. More wrapper features (e.g. most (all?) of the features of the table class could be replacted with a custom class wrapping a struct array, and a string is mostly interchangeable with a cellstr).
While the general trend is that functions get faster, this is not necessarily true for graphics interactions. You will have to do tests yourself on the functions you use. If not, you will have to rely on the performance numbers Mathworks reports. And while they will not lie, they are unlikely to showcase performance regressions.
What I wrote in my comment above still stands: if you want ease of development and nice graphics, use a modern release. If you want blazing fast running code (but fewer development tools and less nice graphics), use Matlab 6.5.
The middle ground between the current release and 6.5 is of course always moving. If you experience severe bottlenecks in modern releases related to graphics, I would suggest something between R2011a and R2014a (which all have a similar UI and have HG1). I would say the next big jump is with the merging of most of the features of the live editor into the normal editor in R2021b. If your computer can handle it, I would currently suggest using R2021b or newer.
So these are the ranges I would distinguish:
  • Matlab 6.5: very fast (but also lacking a lot of features and debugging tools)
  • R2011a-R2014a: relatively new HG1 releases
  • R2014b-R2021a: HG2 releases with the old editor
  • R2021b-newer: HG2 releases with a new editor
@Dyuman Joshi I don't really have a source for this, I just picked this up over the years. There are release notes for every release (the last 5 years should be available online: https://www.mathworks.com/help/matlab/release-notes.html), detailing the most important changes. There isn't really a comparison for the changes for every function.
  4 Comments
Rik
Rik on 29 Jun 2022
No, they are actually not equivalent to handles of graphics objects.
In HG1, handles are stored as a double. You can still see this with figures, where you can also use integers instead of the actual handle object. This allowed much flexibility in terms of storage.
In HG2, handles are stored as objects. This facilitated using the dot-indexing to access properties: Fig.Position instead of get(Fig,'Position').
There are more differences below the surface, but since they are hardly ever relevant for me, I haven't researched the topic thoroughly.
And about the wrapper function: what I mean amount to an interface. For the case of string that would mean you create a class that stores the text internally in a cell array of char vectors, but you use the methods to overload plus to allow this to work. As you can see, you can replicate the same behavior with a cellstr. If you have a week of spare time, you could overload disp to show double quotes and overload all other customizations. At the end you will have the same functionality as string, without using string itself.
["abc";"def"]+[123 456]
ans = 2×2 string array
"abc123" "abc456" "def123" "def456"
overloaded_plus({'abc';'def'},[123 456])
ans = 2×2 cell array
{'abc123'} {'abc456'} {'def123'} {'def456'}
function out=overloaded_plus(arg1,arg2)
% bare-bones example of how you could replicate the plus behavior of the
% string datatype with only cellstr.
% This uses bsxfun and will therefore 'only' work on R2007a or later.
% Swap order if the cellstr is the second argument
if ~iscellstr(arg1)
swapped_args=true;
[arg2,arg1]=deal(arg1,arg2);
else
swapped_args=false;
end
% Convert numeric to cellstr.
if isnumeric(arg2)
arg2=cellfun(@num2str,num2cell(arg2),'UniformOutput',false);
end
% Extend the array sizes with a terrible hack (don't use this).
ones_arg1=ones(size(arg1));
ones_arg2=ones(size(arg2));
result=bsxfun(@plus,ones_arg1,ones_arg2); % Allow implicit expansion.
arg1=repmat(arg1, size(result)./size(ones_arg1) );
arg2=repmat(arg2, size(result)./size(ones_arg2) );
if swapped_args
[arg2,arg1]=deal(arg1,arg2);
end
out=cellfun(@horzcat,arg1,arg2,'UniformOutput',false);
end

Sign in to comment.

Tags

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!