aboutsummaryrefslogtreecommitdiff
path: root/src/cz/crcs/ectester/standalone/libs/jni/c_timing.c
blob: be46398f9ec0f97499f63667baa8efc344b99fc6 (plain) (blame)
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
#include "c_timing.h"
#include <time.h>

#if _POSIX_TIMERS > 0

struct timespec start = {0};
struct timespec end = {0};

jboolean native_timing_supported() {
    return JNI_TRUE;
}

jlong native_timing_resolution() {
    struct timespec timeval;
    clock_getres(CLOCK_MONOTONIC, &timeval);
    return timeval.tv_nsec;
}


void native_timing_start() {
    clock_gettime(CLOCK_MONOTONIC, &start);
}


void native_timing_stop() {
    clock_gettime(CLOCK_MONOTONIC, &end);
}


jlong native_timing_last() {
    jlong res = (end.tv_sec - start.tv_sec) * 1000000000 + (end.tv_nsec - start.tv_nsec);
    if (res < 0) {
        return 0;
    } else {
        return res;
    }
}

#else

jboolean native_timing_supported() {
    return JNI_FALSE;
}

jlong native_timing_resolution() {
    return 0;
}

void native_timing_start() {}

void native_timing_stop() {}

jlong native_timing_last() {
    return 0;
}

#endif