Line data Source code
1 : /*
2 : Copyright (c) 2003, The Regents of the University of California, through
3 : Lawrence Berkeley National Laboratory (subject to receipt of any required
4 : approvals from U.S. Dept. of Energy)
5 :
6 : All rights reserved.
7 :
8 : The source code is distributed under BSD license, see the file License.txt
9 : at the top-level directory.
10 : */
11 :
12 : /*! \file
13 : * \brief Timer functions to record the time used
14 : *
15 : * Returns the time in seconds used by the process.
16 : *
17 : * \note the timer function call is machine dependent. Use conditional
18 : * compilation to choose the appropriate function.
19 : *
20 : * \ingroup Common
21 : */
22 :
23 : #undef USE_TIMES
24 :
25 : #ifdef SUN
26 : /*
27 : * It uses the system call gethrtime(3C), which is accurate to
28 : * nanoseconds.
29 : */
30 : #include <sys/time.h>
31 :
32 : double SuperLU_timer_() {
33 : return ( (double)gethrtime() / 1e9 );
34 : }
35 :
36 : #elif _WIN32
37 :
38 : #include <time.h>
39 :
40 : double SuperLU_timer_()
41 : {
42 : clock_t t;
43 : t=clock();
44 :
45 : return ((double)t)/CLOCKS_PER_SEC;
46 : }
47 :
48 : #elif defined( USE_TIMES )
49 :
50 : #ifndef NO_TIMER
51 : #include <sys/types.h>
52 : #include <sys/times.h>
53 : #include <sys/time.h>
54 : #include <unistd.h>
55 : #endif
56 :
57 : /*! \brief Timer function
58 : *
59 : * \return The time in seconds used by the process.
60 : */
61 : double SuperLU_timer_()
62 : {
63 : #ifdef NO_TIMER
64 : /* no sys/times.h on WIN32 */
65 : double tmp;
66 : tmp = 0.0;
67 : #else
68 : struct tms use;
69 : double tmp;
70 : int clocks_per_sec = sysconf(_SC_CLK_TCK);
71 :
72 : times ( &use );
73 : tmp = use.tms_utime;
74 : tmp += use.tms_stime;
75 : #endif
76 : return (double)(tmp) / clocks_per_sec;
77 : }
78 :
79 : #else
80 :
81 : #include <sys/time.h>
82 : #include <stdlib.h>
83 :
84 : /*! \brief Timer function
85 : *
86 : * \return The time in seconds used by the process.
87 : */
88 0 : double SuperLU_timer_(void)
89 : {
90 : struct timeval tp;
91 : double tmp;
92 0 : gettimeofday(&tp, NULL);
93 0 : tmp = tp.tv_sec + tp.tv_usec/1000000.0;
94 0 : return (tmp);
95 : }
96 :
97 : #endif
|