Documentation for foreach.h, test.h, timer.h and other changes

Change in timer.h. Now cmc_timer_stop will calculate the result so goodbye cmc_timer_calc
This commit is contained in:
Leonardo committed 2020-04-10 22:21:47 -03:00
1 parent aa214d179e
commit 67590790c4
12 files changed
+451 -36

No files matched your search

+61 -1
View File
@@ -1,3 +1,63 @@
# timer.h
Simple code execution utility.
A very simple library that encapsulates `clock()` from `<time.h>`, making life easier.
## cmc_timer
```c
struct cmc_timer
{
clock_t start;
clock_t stop;
double result;
};
```
* `clock_t start` - Start of timing
* `clock_t stop` - End of timing
* `double result` - Result in milliseconds
## cmc_timer_start
Starts the timer by setting `start` with `clock()`.
```c
#define cmc_timer_start(timer)
```
* `timer` - A `struct cmc_timer` variable
## cmc_timer_stop
Sets the `stop` variable with `clock()` and calculates the `result` in milliseconds.
```c
#define cmc_timer_start(timer)
```
* `timer` - A `struct cmc_timer` variable
## Example
```c
#include <stdio.h>
#include "utl/timer.h"
int main(void)
{
struct cmc_timer t;
cmc_timer_start(t);
size_t total = 0;
for (size_t i = 0; i < 1000000000; i++)
total += i;
cmc_timer_stop(t);
printf("Sum took %.0lf milliseconds to calculate\n", t.result);
}
```