The R Project SVN R

Rev

Rev 70779 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 70779 Rev 71334
Line 1... Line 1...
1
/*
1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
2
 *  R : A Computer Language for Statistical Data Analysis
3
 *  Copyright (C) 2000-2015  The R Core Team.
3
 *  Copyright (C) 2000-2016  The R Core Team.
4
 *
4
 *
5
 *  This program is free software; you can redistribute it and/or modify
5
 *  This program is free software; you can redistribute it and/or modify
6
 *  it under the terms of the GNU General Public License as published by
6
 *  it under the terms of the GNU General Public License as published by
7
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  the Free Software Foundation; either version 2 of the License, or
8
 *  (at your option) any later version.
8
 *  (at your option) any later version.
Line 22... Line 22...
22
 
22
 
23
/*
23
/*
24
    Notes on various time functions:
24
    Notes on various time functions:
25
    ===============================
25
    ===============================
26
 
26
 
27
    The current (2008) POSIX recommendation to find the calendar time
27
    The current (2008/13) POSIX recommendation to find the calendar
28
    is to call clock_gettime(), defined in <time.h>.  This may also be
28
    time is to call clock_gettime(), defined in <time.h>.  This may
29
    used to find time since some unspecified starting point
29
    also be used to find the time since some unspecified starting
30
    (e.g. machine reboot), but is not currently so used in R.  It
30
    point (e.g. machine reboot), but is not currently so used in R.
31
    returns in second and nanoseconds, although not necessarily to
31
    It returns in second and nanoseconds, although not necessarily to
32
    more than clock-tick accuracy.
32
    more than clock-tick accuracy.
33
 
33
 
34
    C11 adds 'struct timespec' to <time.h>.  And timespec_get() can get
34
    C11 adds 'struct timespec' to <time.h>.  And timespec_get() which
35
    the current time or interval after a base time.
35
    can get the current time or interval after a base time.
36
 
36
 
37
    The previous POSIX recommendation was gettimeofday(), defined in
37
    The previous POSIX recommendation was gettimeofday(), defined in
38
    <sys/time.h>.  This returns in seconds and microseconds (with
38
    <sys/time.h>.  This returns in seconds and microseconds (with
39
    unspecified granularity).
39
    unspecified granularity).
40
 
40
 
41
    Many systems (including AIX, FreeBSD, Linux, Solaris) have
41
    Many systems (including AIX, FreeBSD, Linux, Solaris) have
42
    clock_gettime().  macOS and Cygwin have gettimeofday().
42
    clock_gettime(): it appeared in macOS 10.12.  macOS and Cygwin
-
 
43
    have gettimeofday().
43
 
44
 
44
    Function time() is C99 and defined in <time.h>.  C99 does not
45
    Function time() is C99 and defined in <time.h>.  C99 does not
45
    mandate the units, but POSIX does (as the number of seconds since
46
    mandate the units, but POSIX does (as the number of seconds since
46
    the epoch: although not mandated, time_t seems always to be an
47
    the epoch: although not mandated, time_t seems always to be an
47
    integer type).
48
    integer type).
Line 59... Line 60...
59
    returns the same time structure as gettimeofday() and on some
60
    returns the same time structure as gettimeofday() and on some
60
    systems offers millisecond resolution.
61
    systems offers millisecond resolution.
61
    It is available on Cygwin, FreeBSD, macOS, Linux and Solaris.
62
    It is available on Cygwin, FreeBSD, macOS, Linux and Solaris.
62
 
63
 
63
    currentTime() (in this file) uses
64
    currentTime() (in this file) uses
64
    clock_gettime(): AIX, FreeBSD, Linux, Solaris
65
    clock_gettime(): AIX, FreeBSD, Linux, Solaris, macOS >= 10.12
65
    gettimeofday():  macOS, Windows, Cygwin
66
    gettimeofday():  macOS <= 10.11, Windows, Cygwin
66
    time() (as ultimate fallback, AFAIK unused).
67
    time() (as ultimate fallback, AFAIK unused).
67
 
68
 
68
    proc.time() uses currentTime() for elapsed time,
69
    proc.time() uses currentTime() for elapsed time,
69
    and getrusage, then times for CPU times on a Unix-alike,
70
    and getrusage, then times for CPU times on a Unix-alike,
70
    GetProcessTimes on Windows.
71
    GetProcessTimes on Windows.