Add timers for measuring elapsed time

This commit is contained in:
2025-09-21 22:07:54 +03:00
parent 9bd2007023
commit b1870bd709
11 changed files with 565 additions and 3 deletions

View File

@@ -0,0 +1,82 @@
=encoding UTF-8
=head1 NAME
BH_Timer - timer utilities
=head1 SYNTAX
#include <BH/Timer.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
This module provides a simple high-resolution timer interface for measuring
elapsed time. The timer uses a monotonic clock source when available, making it
suitable for accurate time measurements, such as profiling or timeouts. It
supports millisecond and nanosecond precision and can be started, restarted,
and queried for elapsed time.
=head1 API CALLS
=head2 BH_TimerNew
BH_Timer *BH_TimerNew(void);
Creates and initializes a new timer object.
Returns a pointer to a newly allocated BH_Timer on success, or NULL on failure.
=head2 BH_TimerFree
void BH_TimerFree(BH_Timer *timer);
Destroys the timer.
=head2 BH_TimerIsMonotonic
int BH_TimerIsMonotonic(BH_Timer *timer);
Checks whether the timer uses a monotonic clock source.
=head2 BH_TimerStart
void BH_TimerStart(BH_Timer *timer);
Starts or resets the timer to begin counting from the current time.
=head2 BH_TimerRestart
int64_t BH_TimerRestart(BH_Timer *timer);
Restarts the timer and returns the number of milliseconds that had elapsed since
the start of the timer.
=head2 BH_TimerMilliseconds
int64_t BH_TimerMilliseconds(BH_Timer *timer);
Returns the number of milliseconds that had elapsed since the start of the
timer.
=head2 BH_TimerNanoseconds
int64_t BH_TimerNanoseconds(BH_Timer *timer);
Returns the number of nanoseconds that had elapsed since the start of the timer.
=head1 SEE ALSO
L<BH>

View File

@@ -20,6 +20,7 @@ HTMLS = BH_Algo.html \
BH_Ray3f.html \
BH_String.html \
BH_Thread.html \
BH_Timer.html \
BH_Unicode.html \
BH_Util.html \
BH_Vec2f.html \
@@ -48,6 +49,7 @@ MANS = BH_Algo.3 \
BH_Ray3f.3 \
BH_String.3 \
BH_Thread.3 \
BH_Timer.3 \
BH_Unicode.3 \
BH_Util.3 \
BH_Vec2f.3 \

View File

@@ -0,0 +1,83 @@
=encoding UTF-8
=head1 НАЗВАНИЕ
BH_Timer - утилиты таймера
=head1 СИНТАКСИС
#include <BH/Timer.h>
cc prog.c -o prog -lbh
=head1 ОПИСАНИЕ
Этот модуль предоставляет простой интерфейс высокоточного таймера для измерения
прошедшего времени. По возможности таймер использует монотонный источник часов,
что делает его подходящим для точных измерений времени, например, профилирования
или тайм-аутов. Поддерживается точность в миллисекундах и наносекундах; таймер
можно запускать, перезапускать и запрашивать прошедшее время.
=head1 API ВЫЗОВЫ
=head2 BH_TimerNew
BH_Timer *BH_TimerNew(void);
Создаёт и инициализирует новый объект таймера.
В случае успеха функция возвращает указатель на новый объект BH_Timer,
или NULL в случае ошибки.
=head2 BH_TimerFree
void BH_TimerFree(BH_Timer *timer);
Уничтожает таймер.
=head2 BH_TimerIsMonotonic
int BH_TimerIsMonotonic(BH_Timer *timer);
Проверяет, использует ли таймер монотонный источник времени.
=head2 BH_TimerStart
void BH_TimerStart(BH_Timer *timer);
Запускает или сбрасывает таймер, начиная отсчёт с текущего момента времени.
=head2 BH_TimerRestart
int64_t BH_TimerRestart(BH_Timer *timer);
Перезапускает таймер и возвращает количество миллисекунд, прошедших с момента
его запуска.
=head2 BH_TimerMilliseconds
int64_t BH_TimerMilliseconds(BH_Timer *timer);
Возвращает количество миллисекунд, прошедших с момента запуска таймера.
=head2 BH_TimerNanoseconds
int64_t BH_TimerNanoseconds(BH_Timer *timer);
Возвращает количество наносекунд, прошедших с момента запуска таймера.
=head1 СМ. ТАКЖЕ
L<BH>

View File

@@ -20,6 +20,7 @@ HTMLS = BH_Algo.html \
BH_Ray3f.html \
BH_String.html \
BH_Thread.html \
BH_Timer.html \
BH_Unicode.html \
BH_Util.html \
BH_Vec2f.html \
@@ -48,6 +49,7 @@ MANS = BH_Algo.3 \
BH_Ray3f.3 \
BH_String.3 \
BH_Thread.3 \
BH_Timer.3 \
BH_Unicode.3 \
BH_Util.3 \
BH_Vec2f.3 \