#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
long s = 1000000000L;
/* 测量一个事件持续的时间*/
int i,j,max,m=0,n=0;
int a[300];
for(i=0; i<300; i++)
a[i]=rand()%100;
//开始
clock_t start, finish;//
double duration;
for(i=0; i<300; i++)
for(j=i; j<300; j++)
{
if (a[j] <a[i])
{
max=a[i];
a[i]=a[j];
a[j]=max;
m+=3;
n++;
}
}
printf ("\n%d\n%d\n",n,m);
//结束
printf( "Time to do %ld empty loops is ", s) ;//
start = clock();
while(s--);
finish = clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC;
printf( "%f seconds\n", duration );
system("pause");
return 0;
}
//十亿次所用时间;4.6340 s
//每循环交换 30933 次;
//每循环比较 10311 次;