运算与时间(Debug、windowsXP、dell dimension 5150)
来源:互联网 发布:网络三国小说排行 编辑:程序博客网 时间:2024/06/05 05:59
- #include <afxwin.h>
- #include <iostream>
- using namespace std;
- //一亿次,用了34秒;一千万次,用了2秒;
- void main()
- {
- CTime t1 = CTime::GetCurrentTime();
- double j =2.345;
- for (int i=0;i<100000000;i++)
- {
- j=j*1.0001234112;
- }
- CTime t2 = CTime::GetCurrentTime();
- CTimeSpan t=t2-t1;
- cout<<t.GetMinutes()<<' '<<t.GetSeconds()<<endl;
- }
以上是double类型的乘法运算,比加法慢了10倍吧!
不过,“赋值操作”也相当耗时间,将j=j*1.0001234112;改成j*1.0001234112; 省略赋值运算的话,十亿次运算,用了3秒。
double类型的乘法运算
- #include <afxwin.h>
- #include <iostream>
- using namespace std;
- //十亿次,用了3秒
- void main()
- {
- CTime t1 = CTime::GetCurrentTime();
- double j =2.345;
- for (int i=0;i<1000000000;i++)
- {
- j*1.0001234112;
- }
- CTime t2 = CTime::GetCurrentTime();
- CTimeSpan t=t2-t1;
- cout<<t.GetMinutes()<<' '<<t.GetSeconds()<<endl;
- }
double类型的次方运算
- #include <afxwin.h>
- #include <math.h>
- #include <iostream>
- using namespace std;
- //一亿次的开方,结果用了4秒
- void main()
- {
- CTime t1 = CTime::GetCurrentTime();
- double j = 999999999.999999999;
- for (int i=0;i<100000000;i++)
- {
- sqrt(j);
- }
- CTime t2 = CTime::GetCurrentTime();
- CTimeSpan t=t2-t1;
- cout<<t.GetMinutes()<<' '<<t.GetSeconds()<<endl;
- }
double类型的加法运算
- #include <afxwin.h>
- #include <iostream>
- using namespace std;
- //十亿次加法,用了2秒,如果要测试更大规模,就得使用循环嵌套了:i溢出了!
- void main()
- {
- CTime t1 = CTime::GetCurrentTime();
- double j =2.345;
- for (int i=0;i<10000000000;i++)
- {
- j+0.2345511;
- }
- CTime t2 = CTime::GetCurrentTime();
- CTimeSpan t=t2-t1;
- cout<<t.GetMinutes()<<' '<<t.GetSeconds()<<endl;
- }
double类型的除法运算
- #include <afxwin.h>
- #include <iostream>
- using namespace std;
- //十亿次除法,用了3秒
- void main()
- {
- CTime t1 = CTime::GetCurrentTime();
- double j =2.345;
- for (int i=0;i<1000000000;i++)
- {
- j/3.11212;
- }
- CTime t2 = CTime::GetCurrentTime();
- CTimeSpan t=t2-t1;
- cout<<t.GetMinutes()<<' '<<t.GetSeconds()<<endl;
- }
当然,如果开启了release模式,运算次数可以有10~100倍的提升。
结论:加法最快,乘法、除法相当;开方最慢,基本上比乘法的运算慢上10倍。
- 运算与时间(Debug、windowsXP、dell dimension 5150)
- 运算与时间(G++、Ubuntu 8.0.4、dell dimension 5150)
- 在Dell Dimension 4700上安装MAC
- windowsXP同步Internet时间
- Dimension
- dimension
- 用debug对DELL笔记本电脑硬盘低格
- Ubuntu 与 DELL
- Dell Dimension 5100 用 Ghost 重装 XP 遇到的问题的对策
- net服务器时间获取与运算;
- Oracle时间运算与日期类型转换
- dell
- DELL
- dell
- dell
- 用DELL的一次DEBUG惨痛经历(两天啊)
- 时间运算
- 运算时间
- 微软JavaScript脚本的加密与解密
- 轮值主席
- 面试中“逃跑”的六个理由
- 数字转化为英文
- C++实现统计字符串出现次数
- 运算与时间(Debug、windowsXP、dell dimension 5150)
- Rails源代码分析(7):ActionController::Filter(1)
- Processing XML with Java site
- Ajax与Struts 联动的下拉框
- NetBeans 时事通讯(刊号 # 34 - Nov 11, 2008)
- WEB遍历文件夹下所有的文件(不遍历文件夹)
- 有关敏捷的若干思考
- SSH登录缓慢解决方法
- 史记《80后传》