1 /*******************************************************************************
2 * Copyright (c) 2018, College of William & Mary
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the College of William & Mary nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE COLLEGE OF WILLIAM & MARY BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * PRIMME: https://github.com/primme/primme
28 * Contact: Andreas Stathopoulos, a n d r e a s _at_ c s . w m . e d u
29 *******************************************************************************
30 * File: wtime.c
31 *
32 * Purpose - Time functions.
33 *
34 ******************************************************************************/
35
36 #define THIS_FILE "../linalg/wtime.c"
37
38 #include <stdlib.h>
39 #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
40 # include <sys/time.h>
41 # include <sys/resource.h>
42 #endif
43
44 #ifndef CHECK_TEMPLATE
45 #include "wtime.h"
46 #endif
47
48 #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
49
primme_wTimer()50 double primme_wTimer() {
51 struct timeval tv;
52 gettimeofday(&tv, NULL);
53 return ((double)tv.tv_sec) + ((double)tv.tv_usec) / (double)1E6;
54 }
55
56 /* In the unlikely event that gettimeofday() is not available, but POSIX is,
57 * we can use the following alternative definition for primme_wTimer,
58 * after including time.h at the top.
59 */
60 /*
61 #include <time.h>
62 double primme_wTimer(int zeroTimer) {
63 static struct timespec ts;
64 static double StartingTime;
65
66 if (zeroTimer) {
67 clock_gettime(CLOCK_REALTIME, &ts);
68 StartingTime = ((double) ts.tv_sec) + ((double) ts.tv_nsec )/(double) 1E9;
69 return StartingTime;
70 }
71 else {
72 clock_gettime(CLOCK_REALTIME, &ts);
73 return ((double) ts.tv_sec) + ((double) ts.tv_nsec ) / (double) 1E9;
74 - StartingTime;
75 }
76 }
77 */
78
79 #else
80
81 #include <Windows.h>
primme_wTimer()82 double primme_wTimer() {
83 return GetTickCount();
84 }
85
86 #endif
87