MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / simple_tic

Function simple_tic

src/util/simple_timer.c:19–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17//------------------------------------------------------------------------------
18
19void simple_tic // returns current time in seconds and nanoseconds
20(
21 double tic [2] // tic [0]: seconds, tic [1]: nanoseconds
22)
23{
24
25 #if defined ( _OPENMP )
26
27 // OpenMP is available; use the OpenMP timer function
28 tic [0] = omp_get_wtime ( ) ;
29 tic [1] = 0 ;
30
31 #elif defined ( __linux__ ) || defined ( __GNU__ )
32
33 // Linux has a very low resolution clock() function, so use the high
34 // resolution clock_gettime instead. May require -lrt
35 struct timespec t ;
36 clock_gettime (CLOCK_MONOTONIC, &t) ;
37 tic [0] = (double) t.tv_sec ;
38 tic [1] = (double) t.tv_nsec ;
39
40 #elif defined ( __MACH__ ) && defined ( __APPLE__ )
41
42 // otherwise, on the Mac, use the MACH timer
43 clock_serv_t cclock ;
44 mach_timespec_t t ;
45 host_get_clock_service (mach_host_self ( ), SYSTEM_CLOCK, &cclock) ;
46 clock_get_time (cclock, &t) ;
47 mach_port_deallocate (mach_task_self ( ), cclock) ;
48 tic [0] = (double) t.tv_sec;
49 tic [1] = (double) t.tv_nsec;
50
51 #else
52
53 // The ANSI C11 clock() function is used instead. This gives the
54 // processor time, not the wallclock time, and it might have low
55 // resolution. It returns the time since some unspecified fixed time
56 // in the past, as a clock_t integer. The clock ticks per second are
57 // given by CLOCKS_PER_SEC. In Mac OSX this is a very high resolution
58 // clock, and clock ( ) is faster than clock_get_time (...) ;
59 clock_t t = clock ( ) ;
60 tic [0] = ((double) t) / ((double) CLOCKS_PER_SEC) ;
61 tic [1] = 0 ;
62
63 #endif
64
65}
66
67//------------------------------------------------------------------------------
68// simple_toc: return the time since the last simple_tic

Calls

no outgoing calls