PAPI 7.1.0.0
Loading...
Searching...
No Matches
timer.h
Go to the documentation of this file.
1/*
2 * This software contains source code provided by NVIDIA Corporation
3 *
4 * According to the Nvidia EULA (compute 5.5 version)
5 * http://developer.download.nvidia.com/compute/cuda/5_5/rel/docs/EULA.pdf
6 *
7 * Chapter 2. NVIDIA CORPORATION CUDA SAMPLES END USER LICENSE AGREEMENT
8 * 2.1.1. Source Code
9 * Developer shall have the right to modify and create derivative works with the Source
10 * Code. Developer shall own any derivative works ("Derivatives") it creates to the Source
11 * Code, provided that Developer uses the Materials in accordance with the terms and
12 * conditions of this Agreement. Developer may distribute the Derivatives, provided that
13 * all NVIDIA copyright notices and trademarks are propagated and used properly and
14 * the Derivatives include the following statement: “This software contains source code
15 * provided by NVIDIA Corporation.”
16 */
17
18#ifndef TIMER_H
19#define TIMER_H
20
21#include <stdlib.h>
22
23#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
24#define WIN32_LEAN_AND_MEAN
25#include <windows.h>
26#else
27#include <sys/time.h>
28#endif
29
30#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
31double PCFreq = 0.0;
32__int64 timerStart = 0;
33#else
35#endif
36
38{
39#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
40 LARGE_INTEGER li;
41
42 if (!QueryPerformanceFrequency(&li))
43 {
44 printf("QueryPerformanceFrequency failed!\n");
45 }
46
47 PCFreq = (double)li.QuadPart/1000.0;
48 QueryPerformanceCounter(&li);
49 timerStart = li.QuadPart;
50#else
51 gettimeofday(&timerStart, NULL);
52#endif
53}
54
55// time elapsed in ms
56double GetTimer()
57{
58#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
59 LARGE_INTEGER li;
60 QueryPerformanceCounter(&li);
61 return (double)(li.QuadPart-timerStart)/PCFreq;
62#else
63 struct timeval timerStop, timerElapsed;
64 gettimeofday(&timerStop, NULL);
65 timersub(&timerStop, &timerStart, &timerElapsed);
66 return timerElapsed.tv_sec*1000.0+timerElapsed.tv_usec/1000.0;
67#endif
68}
69#endif // TIMER_H
70
__time_t tv_sec
__suseconds_t tv_usec
void StartTimer()
Definition: timer.h:37
double GetTimer()
Definition: timer.h:56
struct timeval timerStart
Definition: timer.h:34