Next: , Previous: , Up: C API Reference   [Contents][Index]


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:

  1. timer points to a valid object.
  2. timer->init points to a valid function.
  3. 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:

  1. Call timer->init (timer->data, type, NULL).

Postconditions:

  1. The value timer is valid.
  2. The value timer is not counting.


C Timer Function: void micro_benchmark_timer_init_with_extra (micro_benchmark_timer_definition *timer, micro_benchmark_clock_type type, const void *extra)

Preconditions:

  1. timer points to a valid object.
  2. timer->init points to a valid function.
  3. 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:

  1. Call timer->init (timer->data, type, extra).

Postconditions:

  1. The value timer is valid.
  2. The value timer is not counting.


C Timer Function: void micro_benchmark_timer_cleanup (micro_benchmark_timer timer)

Preconditions:

  1. timer points to a valid object.
  2. timer->cleanup points to a valid function.
  3. The value timer is valid.

Effects:

  1. Call timer->cleanup (timer->data).

Postconditions:

  1. The value timer is not valid.


C Timer Function: micro_benchmark_clock_type micro_benchmark_timer_get_type (micro_benchmark_timer timer)

Preconditions:

  1. timer points to a valid object.
  2. The value timer is valid.

Effects:

  1. None.

Postconditions:

  1. The returned value is timer->data.clock_type;


C Timer Function: const char * micro_benchmark_timer_get_name (micro_benchmark_timer timer)

Preconditions:

  1. timer points to a valid object.
  2. The value timer is valid.

Effects:

  1. None.

Postconditions:

  1. The returned value is timer->data.name;


C Timer Function: micro_benchmark_clock_time micro_benchmark_timer_get_resolution (micro_benchmark_timer timer)

Preconditions:

  1. timer points to a valid object.
  2. The value timer is valid.

Effects:

  1. None.

Postconditions:

  1. 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:

  1. timer points to a valid object.
  2. timer->start points to a valid function.
  3. The value timer is valid.
  4. deadline is non-zero.

Effects:

  1. The timer starts counting time up to deadline.

Postconditions:

  1. timer is running.


C Timer Function: void micro_benchmark_timer_stop (micro_benchmark_timer timer)

Preconditions:

  1. timer points to a valid object.
  2. timer->stop points to a valid function.
  3. The value timer is valid.
  4. timer has been started.

Effects:

  1. timer stops counting time.

Postconditions:

  1. 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:

  1. timer points to a valid object.
  2. timer->restart points to a valid function.
  3. The value timer is valid.
  4. timer has been started.

Effects:

  1. The timer starts counting time again up to the deadline provided by micro_benchmark_timer_start.

Postconditions:

  1. 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:

  1. timer points to a valid object.
  2. timer->is_running points to a valid function.
  3. The value timer is valid.
  4. timer was started.

Effects:

  1. None.

Postconditions:

  1. The returned value is false if the deadline provided to this timer by micro_benchmark_timer_start has not expired.
  2. The returned value is true otherwise.


C Timer Function: micro_benchmark_clock_time micro_benchmark_timer_elapsed (micro_benchmark_timer timer)

Preconditions:

  1. timer points to a valid object.
  2. timer->elapsed points to a valid function.
  3. The value timer is valid.
  4. timer was started.

Effects:

  1. None.

Postconditions:

  1. 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:

  1. 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:

  1. A copy of timer is stored.

Postconditions:

  1. 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:

  1. provider is implemented by the library.
  2. provider is not MICRO_BENCHMARK_TIMER_PROVIDER_USER_PROVIDED.

Effects:

  1. The default timer provider is changed.

Postconditions:

  1. The timers used by the library will have the type provider


C Timer Function: micro_benchmark_timer micro_benchmark_timer_get_default ()

Preconditions:

  1. None.

Effects:

  1. None.

Postconditions:

  1. 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.
  2. If micro_benchmark_timer_set_default was called, the returned value is equivalent to the last value provided to that call.



Next: Utilities Reference, Previous: Data Collection reference, Up: C API Reference   [Contents][Index]