/* SPDX-License-Identifier: LGPL-2.1-only */ /* * The Rin Library – time module, benchmarking section * * Copyright (C) 2019 Gediminas Jakutis */ #include #include #include #include "rin/time.h" #include "rin/definitions.h" #include "time_private.h" static struct bench { int status; struct rusage runtime; struct timespec wall; } bench = {0}; int rin_bench_start(void) { if (bench.status) { return EAGAIN; } bench.status = 1; clock_gettime(RIN_CLOCK_WALL_COUNTER, &bench.wall); getrusage(RUSAGE_SELF, &bench.runtime); return 0; } int rin_bench_stop(struct rin_bench_result *res) { struct timespec wall; struct rusage run; if (!bench.status) { return EAGAIN; } if (!res) { return EINVAL; } getrusage(RUSAGE_SELF, &run); clock_gettime(RIN_CLOCK_WALL_COUNTER, &wall); res->wall = rin_time_sub(&wall, &bench.wall); res->system = rin_timeval_sub(&run.ru_stime, &bench.runtime.ru_stime); res->user = rin_timeval_sub(&run.ru_utime, &bench.runtime.ru_utime); res->total = rin_timeval_add(&res->system, &res->user); bench.status = 0; return 0; }