Why is spdiags() much slower now than in previous versions

9 views (last 30 days)
Mads
Mads on 6 May 2021
Commented: Matt J on 9 May 2021
I have used spdiags() over many years.
Lately MathWorks have updated the script and the response is much slower.
I have compared spdiags() from R2019a with R2021a on a mac.
The older spdiags() runs in my present test 15 to 40 times faster than the latest spdiags().
I wonder what benefit I get from waiting that much longer, for something that involves plugging numbers into a sparse matrix.
  3 Comments
Matt J
Matt J on 9 May 2021
Mads' comment moved here:
When I run your code, I also see no problem. I confirm your results.
I can't send the entire code of mine or the data.
However:
P = 4096
Dm2_... are complex, but with zeros in some places.
Profiler showed quite some time spent in makeSparseGeneral(B, d, A)
version
disp('old')
tic
matrix = spdiags_old([Dm2_,Dm1_,Dp1_,Dp2_],[-2,-1,1,2],P*3,P*3);
toc
disp('new')
tic
matrix = spdiags([Dm2_,Dm1_,Dp1_,Dp2_],[-2,-1,1,2],P*3,P*3);
toc
Two outputs from R2020b for reference:
ans =
'9.9.0.1592791 (R2020b) Update 5'
old
Elapsed time is 0.007126 seconds.
new
Elapsed time is 0.261705 seconds.
ans =
'9.9.0.1592791 (R2020b) Update 5'
old
Elapsed time is 0.006587 seconds.
new
Elapsed time is 0.270015 seconds.
MANY outsputs from R2021a, which by the way runs very unstable.
ans =
'9.10.0.1602886 (R2021a)'
old
Elapsed time is 0.011837 seconds.
new
Elapsed time is 0.250930 seconds.
ans =
'9.10.0.1602886 (R2021a)'
old
Elapsed time is 0.006751 seconds.
new
Elapsed time is 0.249982 seconds.
ans =
'9.10.0.1602886 (R2021a)'
old
Elapsed time is 0.006735 seconds.
new
Elapsed time is 0.250596 seconds.
ans =
'9.10.0.1602886 (R2021a)'
old
Elapsed time is 0.006552 seconds.
new
Elapsed time is 0.254115 seconds.
ans =
'9.10.0.1602886 (R2021a)'
old
Elapsed time is 0.006326 seconds.
new
Elapsed time is 0.249205 seconds.
ans =
'9.10.0.1602886 (R2021a)'
old
Elapsed time is 0.007143 seconds.
new
Elapsed time is 0.256610 seconds.
ans =
'9.10.0.1602886 (R2021a)'
old
Elapsed time is 0.006193 seconds.
new
Elapsed time is 0.254189 seconds.
ans =
'9.10.0.1602886 (R2021a)'
old
Elapsed time is 0.006665 seconds.
new
Elapsed time is 0.267214 seconds.

Sign in to comment.

Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!