![]() |
#2
yuccn2014-07-18 21:07
|

// 点点滴滴.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <time.h>
void test1()
{
int a=1,b=1;
for(int i=0;i<100000;i++)
for(int j=0;j<10000;j++)
a+=b;
}
void test2()
{
int a=1,b=1;
for(int i=0;i<100000;i++)
for(int j=0;j<10000;j++)
a=a+b;
}
int main(int arg,char ** argv)
{
clock_t t1,t2;
float time;
t1=clock();
test1();
t2=clock();
time=(float)(t2-t1)/CLOCKS_PER_SEC;
printf("%fs\n",time);
t1=clock();
test2();
t2=clock();
time=(float)(t2-t1)/CLOCKS_PER_SEC;
printf("%fs\n",time);
return 0;
}
//
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <time.h>
void test1()
{
int a=1,b=1;
for(int i=0;i<100000;i++)
for(int j=0;j<10000;j++)
a+=b;
}
void test2()
{
int a=1,b=1;
for(int i=0;i<100000;i++)
for(int j=0;j<10000;j++)
a=a+b;
}
int main(int arg,char ** argv)
{
clock_t t1,t2;
float time;
t1=clock();
test1();
t2=clock();
time=(float)(t2-t1)/CLOCKS_PER_SEC;
printf("%fs\n",time);
t1=clock();
test2();
t2=clock();
time=(float)(t2-t1)/CLOCKS_PER_SEC;
printf("%fs\n",time);
return 0;
}
只有本站会员才能查看附件,请 登录
只有本站会员才能查看附件,请 登录