Converted cl_perf_timer to use git__timer internally.
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
diff --git a/tests/clar_libgit2_timer.c b/tests/clar_libgit2_timer.c
index f8fa2f3..737506d 100644
--- a/tests/clar_libgit2_timer.c
+++ b/tests/clar_libgit2_timer.c
@@ -7,77 +7,25 @@ void cl_perf_timer__init(cl_perf_timer *t)
memset(t, 0, sizeof(cl_perf_timer));
}
-#if defined(GIT_WIN32)
-
void cl_perf_timer__start(cl_perf_timer *t)
{
- QueryPerformanceCounter(&t->time_started);
+ t->time_started = git__timer();
}
void cl_perf_timer__stop(cl_perf_timer *t)
{
- LARGE_INTEGER time_now;
- QueryPerformanceCounter(&time_now);
+ double time_now = git__timer();
- t->last.QuadPart = (time_now.QuadPart - t->time_started.QuadPart);
- t->sum.QuadPart += (time_now.QuadPart - t->time_started.QuadPart);
+ t->last = time_now - t->time_started;
+ t->sum += t->last;
}
double cl_perf_timer__last(const cl_perf_timer *t)
{
- LARGE_INTEGER freq;
- double fraction;
-
- QueryPerformanceFrequency(&freq);
-
- fraction = ((double)t->last.QuadPart) / ((double)freq.QuadPart);
- return fraction;
+ return t->last;
}
double cl_perf_timer__sum(const cl_perf_timer *t)
{
- LARGE_INTEGER freq;
- double fraction;
-
- QueryPerformanceFrequency(&freq);
-
- fraction = ((double)t->sum.QuadPart) / ((double)freq.QuadPart);
- return fraction;
-}
-
-#else
-
-#include <sys/time.h>
-
-static uint32_t now_in_ms(void)
-{
- struct timeval now;
- gettimeofday(&now, NULL);
- return (uint32_t)((now.tv_sec * 1000) + (now.tv_usec / 1000));
-}
-
-void cl_perf_timer__start(cl_perf_timer *t)
-{
- t->time_started = now_in_ms();
+ return t->sum;
}
-
-void cl_perf_timer__stop(cl_perf_timer *t)
-{
- uint32_t now = now_in_ms();
- t->last = (now - t->time_started);
- t->sum += (now - t->time_started);
-}
-
-double cl_perf_timer__last(const cl_perf_timer *t)
-{
- double fraction = ((double)t->last) / 1000;
- return fraction;
-}
-
-double cl_perf_timer__sum(const cl_perf_timer *t)
-{
- double fraction = ((double)t->sum) / 1000;
- return fraction;
-}
-
-#endif
diff --git a/tests/clar_libgit2_timer.h b/tests/clar_libgit2_timer.h
index b646c7b..0d150e0 100644
--- a/tests/clar_libgit2_timer.h
+++ b/tests/clar_libgit2_timer.h
@@ -1,33 +1,20 @@
#ifndef __CLAR_LIBGIT2_TIMER__
#define __CLAR_LIBGIT2_TIMER__
-#if defined(GIT_WIN32)
-
struct cl_perf_timer
{
/* cummulative running time across all start..stop intervals */
- LARGE_INTEGER sum;
- /* value of last start..stop interval */
- LARGE_INTEGER last;
- /* clock value at start */
- LARGE_INTEGER time_started;
-};
-
-#define CL_PERF_TIMER_INIT {0}
+ double sum;
-#else
+ /* value of last start..stop interval */
+ double last;
-struct cl_perf_timer
-{
- uint32_t sum;
- uint32_t last;
- uint32_t time_started;
+ /* clock value at start */
+ double time_started;
};
#define CL_PERF_TIMER_INIT {0}
-#endif
-
typedef struct cl_perf_timer cl_perf_timer;
void cl_perf_timer__init(cl_perf_timer *t);