matlab里为何double型运算比int64型运算快很多代码1:tica = ones(1000,1000);b = 2*ones(1000,1000);for kkkkkk=1:100 c = a.*b;endtoc;tica = ones(1000,1000,'uint64');b = 2*ones(1000,1000,'uint64');for kkkkkk=1:100 c = a.*b;endtoc结
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 09:17:58
matlab里为何double型运算比int64型运算快很多代码1:tica = ones(1000,1000);b = 2*ones(1000,1000);for kkkkkk=1:100 c = a.*b;endtoc;tica = ones(1000,1000,'uint64');b = 2*ones(1000,1000,'uint64');for kkkkkk=1:100 c = a.*b;endtoc结
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.
这是怎么回事?
matlab里为何double型运算比int64型运算快很多代码1:tica = ones(1000,1000);b = 2*ones(1000,1000);for kkkkkk=1:100 c = a.*b;endtoc;tica = ones(1000,1000,'uint64');b = 2*ones(1000,1000,'uint64');for kkkkkk=1:100 c = a.*b;endtoc结
我也不知道,不过猜想是不是因为 int64 在存储数据上花费了太多的时间?