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 ) { |
---|
22 | // struct tms now; |
---|
23 | // times( &now ); |
---|
24 | // printf( "time used : user (" ); |
---|
25 | |
---|
26 | // unsigned int minutes = (now.tms_utime-_since->tms_utime)/CLOCKS_PER_SEC / 60; |
---|
27 | // unsigned int hours = minutes / 60; |
---|
28 | // minutes -= hours * 60; |
---|
29 | // if (hours > 0) printf( "%uh ", hours ); |
---|
30 | // if (minutes > 0) printf( "%um ", minutes ); |
---|
31 | // printf( "%.3fs) system (", (float)(now.tms_utime-_since->tms_utime)/CLOCKS_PER_SEC-(hours*3600)-(minutes*60) ); |
---|
32 | |
---|
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)\n", (float)(now.tms_stime-_since->tms_stime)/CLOCKS_PER_SEC-(hours*3600)-(minutes*60) ); |
---|
39 | |
---|
40 | // fflush(stdout); |
---|
41 | // } |
---|
42 | |
---|
43 | void PS_print_time_diff( const struct tms *_since, const char *_before, const char *_after) { |
---|
44 | struct tms now; |
---|
45 | times( &now ); |
---|
46 | if (_before) printf( "%s", _before ); |
---|
47 | printf( "time used : user (" ); |
---|
48 | |
---|
49 | unsigned int minutes = (now.tms_utime-_since->tms_utime)/CLOCKS_PER_SEC / 60; |
---|
50 | unsigned int hours = minutes / 60; |
---|
51 | minutes -= hours * 60; |
---|
52 | if (hours > 0) printf( "%uh ", hours ); |
---|
53 | if (minutes > 0) printf( "%um ", minutes ); |
---|
54 | printf( "%.3fs) system (", (float)(now.tms_utime-_since->tms_utime)/CLOCKS_PER_SEC-(hours*3600)-(minutes*60) ); |
---|
55 | minutes = (now.tms_stime-_since->tms_stime)/CLOCKS_PER_SEC / 60; |
---|
56 | hours = minutes / 60; |
---|
57 | minutes -= hours * 60; |
---|
58 | if (hours > 0) printf( "%uh ", hours ); |
---|
59 | if (minutes > 0) printf( "%um ", minutes ); |
---|
60 | printf( "%.3fs)", (float)(now.tms_stime-_since->tms_stime)/CLOCKS_PER_SEC-(hours*3600)-(minutes*60) ); |
---|
61 | |
---|
62 | if (_after) { |
---|
63 | printf( "%s", _after ); |
---|
64 | } else { |
---|
65 | printf( "\n" ); |
---|
66 | } |
---|
67 | fflush( stdout ); |
---|
68 | } |
---|
69 | |
---|
70 | |
---|
71 | |
---|