||
减少for循环,用向量乘法
clc; clear all; tic n=5000; A=ones(n,n); B=ones(n,n); H1=ones(n,n); H1=A.*B; toc maxNumCompThreads(2*maxNumCompThreads); tic n=5000; A=ones(n,n); B=ones(n,n); H1=ones(n,n); H1=A.*B; toc tic n=5000; A=ones(n,n); B=ones(n,n); H2=ones(n,n); for i=1:n for j=1:n H2(i)= A(i,j)*B(i,j); end end toc % maxNumCompThreads(2*maxNumCompThreads); tic n=5000; A=ones(n,n); B=ones(n,n); H2=ones(n,n); for i=1:n for j=1:n H2(i)= A(i,j)*B(i,j); end end toc
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-12-25 23:40
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社