问题描述:
matlab里为何double型运算比int64型运算快很多
代码1:
tic
a = ones(1000,1000);b = 2*ones(1000,1000);
for kkkkkk=1:100
c = a.*b;
end
toc;tic
a = ones(1000,1000,'uint64');b = 2*ones(1000,1000,'uint64');
for kkkkkk=1:100
c = a.*b;
end
toc
结果是:
Elapsed time is 0.517186 seconds.
Elapsed time is 1.052175 seconds.
代码2:
tic
for kkkkkk=1:1000000
a = 1234*1e7;
end
toc;tic
a0 = uint64(1234);
for kkkkkk=1:1000000
a = a0*1e7;
end
toc
结果是:
Elapsed time is 0.004122 seconds.
Elapsed time is 5.845563 seconds.
这是怎么回事?
代码1:
tic
a = ones(1000,1000);b = 2*ones(1000,1000);
for kkkkkk=1:100
c = a.*b;
end
toc;tic
a = ones(1000,1000,'uint64');b = 2*ones(1000,1000,'uint64');
for kkkkkk=1:100
c = a.*b;
end
toc
结果是:
Elapsed time is 0.517186 seconds.
Elapsed time is 1.052175 seconds.
代码2:
tic
for kkkkkk=1:1000000
a = 1234*1e7;
end
toc;tic
a0 = uint64(1234);
for kkkkkk=1:1000000
a = a0*1e7;
end
toc
结果是:
Elapsed time is 0.004122 seconds.
Elapsed time is 5.845563 seconds.
这是怎么回事?
问题解答:
我来补答展开全文阅读