Linux下得到毫秒级时间--C语言实现
原文链接: http://www.cnblogs.com/nwf5d/archive/2011/06/03/2071247.html
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
int main(int argc, char *argv[])
{
printf("Hello, world!
");
struct timeval tvafter,tvpre;
struct timezone tz;
int sum = 0;
int i=0;
gettimeofday (&tvpre , &tz);
for(i = 0; i < 100000000; i++)
{
sum += i;
}
gettimeofday (&tvafter , &tz);
printf("sum=%d 花费时间:%d
",sum, (tvafter.tv_sec-tvpre.tv_sec)*1000+(tvafter.tv_usec-tvpre.tv_usec)/1000);
return EXIT_SUCCESS;