|
|
1.1 root 1: /* time programs */
2: # include "stdio.h"
3: # include "sys/types.h"
4: # ifndef SVR2
5: # include "sys/timeb.h"
6: # endif
7: struct tbuffer {
8: long proc_user_time;
9: long proc_system_time;
10: long child_user_time;
11: long child_system_time;
12: };
13: static long start, user, system;
14: tick()
15: {
16: struct tbuffer tx;
17: # ifndef SVR2
18: struct timeb tp;
19: ftime (&tp);
20: times (&tx);
21: start = tp.time*1000+tp.millitm;
22: # else
23: start = times(&tx);
24: # endif
25: user = tx.proc_user_time;
26: system = tx.proc_system_time;
27: }
28: tock()
29: {
30: struct tbuffer tx;
31: float lap, use, sys;
32: # ifndef SVR2
33: struct timeb tp;
34: ftime (&tp);
35: times (&tx);
36: lap = (tp.time*1000+tp.millitm-start)/1000.;
37: # else
38: lap = (times(&tx)-start)/60.;
39: # endif
40: if (start==0) return;
41: use = (tx.proc_user_time - user)/60.;
42: sys = (tx.proc_system_time - system)/60.;
43: printf("Elapsed %.2f CPU %.2f (user %.2f, sys %.2f)\n",
44: lap, use+sys, use, sys);
45: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.