计算机乘除法速度测试程序

来源:互联网 发布:炒股软件二次开发 编辑:程序博客网 时间:2024/05/16 12:08
// gameTest.cpp : 定义控制台应用程序的入口点。
//


#include "stdafx.h"
#include <Windows.h>
#include <iostream>
using namespace std;


void Test1();


int _tmain(int argc, _TCHAR* argv[])
{
Test1();
getchar();
return 0;
}


//测试乘法与除法哪个快
void Test1()
{
int t0, t1, t2, t3,i;
double m = 0.0;


t0 = GetTickCount();
for (i = 0; i < 1000000; i++)
m = 101.0 / 3.0;
t1 = GetTickCount();
for (i = 0; i < 1000000; i++)
m = 101.0 * 3.0;
t2 = GetTickCount();

cout << "1000000次乘法:" << t2 - t1 << "\n1000000次除法:" << t1 - t0 << endl;

}

运行后可以看出来:乘法比除法快得多,所以编程尽量用乘法。


原创粉丝点击