このページを編集する際は,編集に関する方針に従ってください.[]
概要[]
- gcc-4.1.0/libiberty/getruntime.cにて定義
- 経過した時間をマイクロ秒単位で返す
引数[]
- void
実装[]
80 /*
81
82 @deftypefn Replacement long get_run_time (void)
83
84 Returns the time used so far, in microseconds. If possible, this is
85 the time used by this process, else it is the elapsed time since the
86 process started.
87
88 @end deftypefn
89
90 */
91
92 long
93 get_run_time (void)
94 {
95 #if defined (HAVE_GETRUSAGE) && defined (HAVE_SYS_RESOURCE_H)
96 struct rusage rusage;
97
98 getrusage (0, &rusage);
99 return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec
100 + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec);
101 #else /* ! HAVE_GETRUSAGE */
102 #ifdef HAVE_TIMES
103 struct tms tms;
104
105 times (&tms);
106 return (tms.tms_utime + tms.tms_stime) * (1000000 / GNU_HZ);
107 #else /* ! HAVE_TIMES */
108 /* Fall back on clock and hope it's correctly implemented. */
109 const long clocks_per_sec = CLOCKS_PER_SEC;
110 if (clocks_per_sec <= 1000000)
111 return clock () * (1000000 / clocks_per_sec);
112 else
113 return clock () / clocks_per_sec;
114 #endif /* HAVE_TIMES */
115 #endif /* HAVE_GETRUSAGE */
116 }