📄 time.c
字号:
#include <stdio.h>#include <sys/types.h>#include <sys/times.h>#include <unistd.h>static void pr_times(clock_t, struct tms *,struct tms *);static void do_cmd(char *);int main(int argc,char *argv[]){ int i; setbuf(stdout,NULL); if(argc < 2) { printf("-wsh: syntax error near unexpected token 'newline'\n"); exit(0); } for(i = 1;i < argc;i++) do_cmd(argv[i]); exit(0);}static void do_cmd(char *cmd){ struct tms tmsstart,tmsend; clock_t start,end; int status; if((start = times(&tmsstart)) == -1) perror("times error"); if((status = system(cmd)) < 0) perror("system() error"); if((end = times(&tmsend)) == -1) perror("times error"); pr_times(end-start,&tmsstart,&tmsend); exit(status);}static void pr_times(clock_t real,struct tms *tmsstart,struct tms *tmsend){ static long clktck = 0; if(clktck == 0) if((clktck = sysconf(_SC_CLK_TCK)) < 0) perror("sysconf error"); printf("\n"); printf("real%8.3f\n",real/(double)clktck); printf("user%8.3f\n", (tmsend->tms_utime - tmsstart->tms_utime)/(double)clktck); printf("sys %8.3f\n", (tmsend->tms_stime - tmsstart->tms_stime)/(double)clktck);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -