#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
struct timeval tpstart,tpend;
double timeuse;
void timebegin()
{
gettimeofday(&tpstart,NULL);//记录开始计时时间tpstart
}
void timeend(const char *str)
{
gettimeofday(&tpend,NULL);//记录计时结束时间tpend
timeuse=1000000*(tpend.tv_sec-tpstart.tv_sec)+tpend.tv_usec-tpstart.tv_usec;
timeuse/=1000000;
printf("%s %lf s\n",str, timeuse);
}
int main()
{
int count = 4000 * 3000;
float *array = (float *) calloc(4000,3000 * sizeof(float));
timebegin();
int i=0;
for (i = 0; i < count; ++i)
{
array[i] = 12.56*123.6 + 12.3;
}
timeend("time use ");
free(array);
array = NULL;
return 0;
}