summaryrefslogtreecommitdiffhomepage
path: root/tests/tools/now.c
blob: c626b4e5a00c0cb715ac6e2143e5d410390b8f64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
 * @file now.c
 * @brief Microseconds since the epoch, for the start-up benchmark.
 *
 * `bench/startup.sh` needs a wall clock finer than a second: one
 * `shell -c :` costs milliseconds, and /bin/date on z/OS has no
 * sub-second format.  Only a difference of two readings is wanted, and
 * the arithmetic that takes it is 32-bit on z/OS sh, so the value is
 * reduced to a 1000-second window: enough for any one benchmark run,
 * and it fits in 2^31.
 */
#include <stdio.h>
#include <time.h>

int main(void) {
    struct timespec ts;
    if (clock_gettime(CLOCK_REALTIME, &ts) < 0)
        return 1;
    printf("%lld\n", (long long)(ts.tv_sec % 1000) * 1000000 + ts.tv_nsec / 1000);
    return 0;
}