求程序执行时间的函数解决方法

求程序执行时间的函数
想知道一个程序运行的时间,但不知道是那个函数,求高手帮忙啊!

------解决方案--------------------
clock_t 和 clock()函数(包含time.h)

clock_t time;
......
......
......
time = clock();
double start_time = (double)time;
......
time = clock();
double end_time = (double)time;

double timeSpend = end_time - start_time;
------解决方案--------------------
C/C++ code

unsigned long startime= GetTickCount();
Sleep(3000);
unsigned long time=GetTickCount()-startime;
printf("%d",time);

------解决方案--------------------
C/C++ code
AME
       clock - Determine processor time

SYNOPSIS
       #include <time.h>

       clock_t clock(void);

DESCRIPTION
       The clock() function returns an approximation of processor time used by the program.

RETURN VALUE
       The  value  returned is the CPU time used so far as a clock_t; to get the number of seconds used, divide by CLOCKS_PER_SEC.  If the processor time
       used is not available or its value cannot be represent

------解决方案--------------------
说实话,CPU时间不能拿来评价程序的real time, 多核CPU或者其他技术什么的,CPU根本不是评价标准.

建议直接获取时间差,哪一个足够精确我也不知道.

owenliang@linux-7lsl:~/csdn/src> time ./main
asdf
asdf
max_chars : 4 
0 0 0

real 0m1.528s
user 0m0.000s
sys 0m0.000s
------解决方案--------------------
gettimeofday还不错,精确到微妙。

C/C++ code
owenliang@linux-7lsl:~/csdn/src> ./main
asdf
asdf
max_chars : 4 
real time : 0 secs 717 msecs 
owenliang@linux-7lsl:~/csdn/src> time ./main
asdf
asdf
asdf
asdf
max_chars : 4 
real time : 1 secs 344 msecs 

real    0m1.346s
user    0m0.000s
sys     0m0.000s
owenliang@linux-7lsl:~/csdn/src>