|
1 | | -# Benchmark |
| 1 | +# Profiler |
2 | 2 |
|
3 | 3 | A simple library to benchmark your code. |
4 | 4 |
|
5 | | -## Compiling |
6 | | - |
7 | | -- `mkdir build` |
8 | | -- `cd build` |
9 | | -- `cmake ..` |
10 | | -- `make` |
11 | | - |
12 | 5 | ## Usage example |
13 | 6 |
|
14 | 7 | ```c |
15 | 8 | #include <stdio.h> |
16 | | -#include "benchmark.h" |
| 9 | +#define PROFILER |
| 10 | +#include "profiler.h" |
17 | 11 |
|
18 | | -int main(int argc, char **argv) |
| 12 | +static void random_func(void) |
19 | 13 | { |
20 | | - (void) argc; |
21 | | - (void) argv; |
22 | | - |
23 | | - /* Create an initate the stopclock */ |
24 | | - StopClock sclock; |
25 | | - sclock_init(&sclock); |
26 | | - |
27 | | - sclock_start(&sclock); |
28 | | - |
29 | | - /* Execute some code */ |
30 | | - |
31 | | - sclock_checkpoint(&sclock, "First part"); |
| 14 | + TIME_FUNC_BEGIN(); |
32 | 15 |
|
33 | | - /* Execute some more code */ |
| 16 | + /* Your code goes here... */ |
34 | 17 |
|
35 | | - sclock_checkpoint(&sclock, "Second part"); |
36 | | - |
37 | | - /* Execute even more code */ |
| 18 | + TIME_FUNC_END(); |
| 19 | +} |
38 | 20 |
|
39 | | - sclock_checkpoint(&sclock, "Third part"); |
| 21 | +int main(int argc, char **argv) |
| 22 | +{ |
| 23 | + PROFILER_SETUP(); |
| 24 | + (void) argc; |
| 25 | + (void) argv; |
40 | 26 |
|
41 | | - /* Stop the clock */ |
42 | | - sclock_stop(&sclock); |
| 27 | + random_func(); |
43 | 28 |
|
44 | | - /* Output the results */ |
45 | | - sclock_print(&sclock, stdout); |
| 29 | + TIME_BLOCK_BEGIN(block_name); |
| 30 | + /* Your code goes here */ |
| 31 | + TIME_BLOCK_END(block_name); |
46 | 32 |
|
47 | | - /* Clean up */ |
48 | | - sclock_destroy(&sclock); |
| 33 | + PROFILER_STOP(stdout); |
49 | 34 | } |
50 | 35 | ``` |
51 | 36 |
|
52 | 37 | ### Example output |
53 | 38 |
|
54 | | -``` |
55 | | - ===== Benchmarks : ===== |
56 | | - First part : 5916119358 95.54% |
57 | | - Second part : 6940092 0.17% |
58 | | - Third part : 265775256 4.29% |
59 | | - Remaining time : 3478810 0.00% |
| 39 | +```text |
| 40 | + ===== Benchmarks : ===== |
| 41 | + Total time : 106691427524 (34.7301 s) |
| 42 | + run_game_update[1933] : 20781332 0.02% (2.53% w/children) |
| 43 | + update_before_particle_engine[1933] : 195193852 0.18% |
| 44 | + update_after_particle_engine[1933] : 1123800376 1.05% |
| 45 | + particle_engine_update[1933] : 1354889225 1.27% |
60 | 46 | ``` |
61 | 47 |
|
62 | 48 | ## How it works |
63 | 49 |
|
64 | 50 | Under the hood `benchmark` is using the `RDTSC` assembly instruction to time |
65 | | -things. During the `sclock_init` the number of pseudo clocks used in `RDTSC` |
66 | | -occur in one second (over 300ms). This is a rough estimate but usually aligns |
67 | | -well with the Ghz number specified on the running computers cpu. |
68 | | -
|
69 | | -## API |
70 | | -
|
71 | | -> TODO: Generate API and link to it here |
| 51 | +things. Then there's a bunch of other logic that I don't remember because it's |
| 52 | +been a while since I wrote it. |
0 commit comments