matlab中double 和single數據類型的差異
matlab中double 和single數據類型的差異
double數據類型佔用8個字節,single數據類型佔4個字節。因此用single會更快一些。(能夠這麼理解,就像你作8位數乘法跟作4位數乘法同樣~確定作4位數的運算更快一些嘛)html
- a=randn(3,3)
- a =
- 0.8404 -0.5445 0.4900
- -0.8880 0.3035 0.7394
- 0.1001 -0.6003 1.7119
- >> b=single(a)
- b =
- 0.8404 -0.5445 0.4900
- -0.8880 0.3035 0.7394
- 0.1001 -0.6003 1.7119
- >> c=randn(3,3);
- >> tic,a*c,toc;
- ans =
- 0.5899 2.1930 -1.6388
- -1.0974 -0.8179 -1.1239
- -0.1730 2.4243 -4.2069
- Elapsed time is 0.199251 seconds.
- >> tic,b*c,toc;
- ans =
- 0.5899 2.1930 -1.6388
- -1.0974 -0.8179 -1.1239
- -0.1730 2.4243 -4.2069
- Elapsed time is 0.002739 seconds.
- >> class(a)
- ans =
- double
- >> class(b)
- ans =
- single
可見,single類型數據運算速度明顯比double型數據快不少。spa