File: timers.c

package info (click to toggle)
python-line-profiler 2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 284 kB
  • sloc: python: 694; ansic: 53; makefile: 17
file content (60 lines) | stat: -rw-r--r-- 1,045 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "Python.h"

/* The following timer code comes from Python 2.5.2's _lsprof.c */

#if !defined(HAVE_LONG_LONG)
#error "This module requires long longs!"
#endif

/*** Selection of a high-precision timer ***/

#ifdef MS_WINDOWS

#include <windows.h>

PY_LONG_LONG
hpTimer(void)
{
        LARGE_INTEGER li;
        QueryPerformanceCounter(&li);
        return li.QuadPart;
}

double
hpTimerUnit(void)
{
        LARGE_INTEGER li;
        if (QueryPerformanceFrequency(&li))
                return 1.0 / li.QuadPart;
        else
                return 0.000001;  /* unlikely */
}

#else  /* !MS_WINDOWS */

#if (defined(PYOS_OS2) && defined(PYCC_GCC))
#include <sys/time.h>
#else
#include <sys/resource.h>
#include <sys/times.h>
#endif

PY_LONG_LONG
hpTimer(void)
{
        struct timeval tv;
        PY_LONG_LONG ret;
        gettimeofday(&tv, (struct timezone *)NULL);
        ret = tv.tv_sec;
        ret = ret * 1000000 + tv.tv_usec;
        return ret;
}

double
hpTimerUnit(void)
{
        return 0.000001;
}

#endif  /* MS_WINDOWS */