4.6 Timer Reference
Timers are devices triggered after some time.
- C Data Type: micro_benchmark_timer_data { void *ptr, const char *name, micro_benchmark_clock_type type, micro_benchmark_clock_time resolution } ¶
-
Timer instance data.
- C Function Type: micro_benchmark_timer_init_fun ¶
-
Its prototype is void (*) (micro_benchmark_timer_data *,
micro_benchmark_clock_type, const void *)
.
- C Function Type: micro_benchmark_timer_cleanup_fun ¶
-
Its prototype is void (*) (const micro_benchmark_timer_data *)
.
- C Function Type: micro_benchmark_timer_start_fun ¶
-
Its prototype is void (*) (void *, micro_benchmark_clock_time)
.
- C Function Type: micro_benchmark_timer_stop_fun ¶
-
Its prototype is void (*) (void *)
.
- C Function Type: micro_benchmark_timer_restart_fun ¶
-
Its prototype is void (*) (void *)
.
- C Function Type: micro_benchmark_timer_running_fun ¶
-
Its prototype is bool (*) (void *)
.
- C Function Type: micro_benchmark_timer_elapsed_fun ¶
-
Its prototype is micro_benchmark_clock_time (*) (void *)
.
- C Data Type: micro_benchmark_timer_definition {
micro_benchmark_timer_data
data, micro_benchmark_timer_init_fun
init, micro_benchmark_timer_cleanup_fun
release, micro_benchmark_timer_start_fun
start, micro_benchmark_timer_stop_fun
stop, micro_benchmark_timer_restart_fun
restart, micro_benchmark_timer_running_fun
is_running, micro_benchmark_timer_elapsed_fun
elapsed } ¶
-
Timer definition.
- C Data Type: micro_benchmark_timer ¶
-
Pointer to a timer instance.
- C Timer Function: void micro_benchmark_timer_init (micro_benchmark_timer_definition *timer, micro_benchmark_clock_type type) ¶
-
Preconditions:
- timer points to a valid object.
- timer->init points to a valid function.
- The value timer is not valid. This means one of the following
conditions:
- No value equivalent to timer has been provided as a parameter to
micro_benchmark_timer_init
or
micro_benchmark_timer_init_with_extra
.
- Each call to
micro_benchmark_timer_init
or
micro_benchmark_timer_init_with_extra
with a value equivalent
to timer as its parameter has been followed by a call to
micro_benchmark_timer_cleanup
with a value equivalent to
timer as its parameter.
Effects:
- Call
timer->init (timer->data, type, NULL)
.
Postconditions:
- The value timer is valid.
- The value timer is not counting.
-
Preconditions:
- timer points to a valid object.
- timer->init points to a valid function.
- The value timer is not valid. This means one of the following
conditions:
- No value equivalent to timer has been provided as a parameter to
micro_benchmark_timer_init
or
micro_benchmark_timer_init_with_extra
.
- Each call to
micro_benchmark_timer_init
or
micro_benchmark_timer_init_with_extra
with a value equivalent
to timer as its parameter has been followed by a call to
micro_benchmark_timer_cleanup
with a value equivalent to
timer as its parameter.
Effects:
- Call timer->init (timer->data, type, extra).
Postconditions:
- The value timer is valid.
- The value timer is not counting.
- C Timer Function: void micro_benchmark_timer_cleanup (micro_benchmark_timer timer) ¶
-
Preconditions:
- timer points to a valid object.
- timer->cleanup points to a valid function.
- The value timer is valid.
Effects:
- Call timer->cleanup (timer->data).
Postconditions:
- The value timer is not valid.
- C Timer Function: micro_benchmark_clock_type micro_benchmark_timer_get_type (micro_benchmark_timer timer) ¶
-
Preconditions:
- timer points to a valid object.
- The value timer is valid.
Effects:
- None.
Postconditions:
- The returned value is timer->data.clock_type;
- C Timer Function: const char * micro_benchmark_timer_get_name (micro_benchmark_timer timer) ¶
-
Preconditions:
- timer points to a valid object.
- The value timer is valid.
Effects:
- None.
Postconditions:
- The returned value is
timer->data.name
;
- C Timer Function: micro_benchmark_clock_time micro_benchmark_timer_get_resolution (micro_benchmark_timer timer) ¶
-
Preconditions:
- timer points to a valid object.
- The value timer is valid.
Effects:
- None.
Postconditions:
- The returned value is
timer->data.resolution
;
- C Timer Function: void micro_benchmark_timer_start (cro_benchmark_timer timer, micro_benchmark_clock_time deadline) ¶
-
Preconditions:
- timer points to a valid object.
- timer->start points to a valid function.
- The value timer is valid.
- deadline is non-zero.
Effects:
- The timer starts counting time up to deadline.
Postconditions:
- timer is running.
- C Timer Function: void micro_benchmark_timer_stop (micro_benchmark_timer timer) ¶
-
Preconditions:
- timer points to a valid object.
- timer->stop points to a valid function.
- The value timer is valid.
- timer has been started.
Effects:
- timer stops counting time.
Postconditions:
- The running status of timer is fixed up to the next call to
micro_benchmark_timer_restart
or
micro_benchmark_timer_stop
.
- C Timer Function: void micro_benchmark_timer_restart (micro_benchmark_timer timer) ¶
-
Preconditions:
- timer points to a valid object.
- timer->restart points to a valid function.
- The value timer is valid.
- timer has been started.
Effects:
- The timer starts counting time again up to the deadline provided by
micro_benchmark_timer_start
.
Postconditions:
- timer is running if it was running when the last call to
micro_benchmark_timer_stop
was performed.
- C Timer Function: bool micro_benchmark_timer_is_running (micro_benchmark_timer timer) ¶
-
Preconditions:
- timer points to a valid object.
- timer->is_running points to a valid function.
- The value timer is valid.
- timer was started.
Effects:
- None.
Postconditions:
- The returned value is
false
if the deadline provided to this
timer by micro_benchmark_timer_start
has not expired.
- The returned value is
true
otherwise.
- C Timer Function: micro_benchmark_clock_time micro_benchmark_timer_elapsed (micro_benchmark_timer timer) ¶
-
Preconditions:
- timer points to a valid object.
- timer->elapsed points to a valid function.
- The value timer is valid.
- timer was started.
Effects:
- None.
Postconditions:
- The returned value is the accumulated time elapsed between calls of
micro_benchmark_timer_start
and
micro_benchmark_timer_stop
, and the following pairs of calls to
micro_benchmark_timer_restart
and
micro_benchmark_timer_stop
, up to deadline.
- C Timer Function: void micro_benchmark_timer_set_default (micro_benchmark_timer timer) ¶
-
Preconditions:
- Either:
- timer points to a valid chronometer.
- timer points to an object of type
micro_benchmark_timer_definition
where at least all the
function fields have been filled with a valid function.
Effects:
- A copy of timer is stored.
Postconditions:
- The timers used by the library will have a type equivalent to
timer
- C Timer Function: void micro_benchmark_timer_set_default_provider (micro_benchmark_timer_provider provider) ¶
-
Preconditions:
- provider is implemented by the library.
- provider is not
MICRO_BENCHMARK_TIMER_PROVIDER_USER_PROVIDED
.
Effects:
- The default timer provider is changed.
Postconditions:
- The timers used by the library will have the type provider
- C Timer Function: micro_benchmark_timer micro_benchmark_timer_get_default () ¶
-
Preconditions:
- None.
Effects:
- None.
Postconditions:
- The returned value is the effective type of the timers created by
micro_benchmark_timer_create_default
and the ones created by
providing the type MICRO_BENCHMARK_TIMER_PROVIDER_DEFAULT
on
micro_benchmark_timer_create
.
- If
micro_benchmark_timer_set_default
was called, the returned
value is equivalent to the last value provided to that call.