#include "stdio.h"
#include "sys/times.h"
#include "time.h"
#include "unistd.h"
static void do_cmd(char *);
int main(int argc,char *argv[])
{
if(argc == 1)
{
printf("Usage: %s cmd\n",argv[0]);
exit(1);
}
struct tms tmsstart,tmsend;
clock_t start,end;
start=times(&tmsstart);
system(argv[1]);
end=times(&tmsend);
clock_t real=end-start;
// system base start
static long base= 0;
base=sysconf( _SC_CLK_TCK );
// system base end
printf("real: %7.2f\n",real/(double) base);
printf("user: %7.2f\n",(tmsend.tms_utime-tmsstart.tms_utime)/(double) base);
printf("cpu: %7.2f\n",(tmsend.tms_stime-tmsstart.tms_stime)/(double) base);
}
转载于:https://blog.51cto.com/biott/1129656