ARB
ps_tools.cxx
Go to the documentation of this file.
1 // ==================================================================== //
2 // //
3 // File : ps_tools.cxx //
4 // Purpose : remove duplicated code //
5 // //
6 // //
7 // Coded by Ralf Westram (coder@reallysoft.de) in October 2004 //
8 // Copyright Department of Microbiology (Technical University Munich) //
9 // //
10 // Visit our web site at: http://www.arb-home.de/ //
11 // //
12 // ==================================================================== //
13 
14 #include "ps_tools.hxx"
15 
16 #include <cstdio>
17 #include <cstdlib>
18 #include <ctime>
19 #include <sys/times.h>
20 
21 void PS_print_time_diff(const struct tms *_since, const char *_before, const char *_after) {
22  struct tms now;
23  times(&now);
24  if (_before) printf("%s", _before);
25  printf("time used : user (");
26 
27  unsigned int minutes = (now.tms_utime-_since->tms_utime)/CLOCKS_PER_SEC / 60;
28  unsigned int hours = minutes / 60;
29  minutes -= hours * 60;
30  if (hours > 0) printf("%uh ", hours);
31  if (minutes > 0) printf("%um ", minutes);
32  printf("%.3fs) system (", (float)(now.tms_utime-_since->tms_utime)/CLOCKS_PER_SEC-(hours*3600)-(minutes*60));
33  minutes = (now.tms_stime-_since->tms_stime)/CLOCKS_PER_SEC / 60;
34  hours = minutes / 60;
35  minutes -= hours * 60;
36  if (hours > 0) printf("%uh ", hours);
37  if (minutes > 0) printf("%um ", minutes);
38  printf("%.3fs)", (float)(now.tms_stime-_since->tms_stime)/CLOCKS_PER_SEC-(hours*3600)-(minutes*60));
39 
40  if (_after) {
41  printf("%s", _after);
42  }
43  else {
44  printf("\n");
45  }
46  fflush(stdout);
47 }
48 
49 
50 
void PS_print_time_diff(const struct tms *_since, const char *_before, const char *_after)
Definition: ps_tools.cxx:21
fflush(stdout)