benchmark.c

Basic benchmarking library in C
git clone git://git.finwo.net/lib/benchmark.c
Log | Files | Refs | README | LICENSE

README.md (1800B)


      1 benchmark
      2 =========
      3 
      4 Small benchmarking helper library
      5 
      6 This library makes use of [dep](https://github.com/finwo/dep) to manage it's
      7 dependencies and exports.
      8 
      9 Installation
     10 ------------
     11 
     12 ```sh
     13 dep add finwo/benchmark
     14 dep install
     15 ```
     16 
     17 After that, simply add `include lib/.dep/config.mk` in your makefile and include
     18 the header file by adding `#include "finwo/benchmark.h`.
     19 
     20 Features
     21 --------
     22 
     23 - Markdown-compatible output
     24 
     25 Example
     26 -------
     27 
     28 ```c
     29 #include "finwo/benchmark.h"
     30 
     31 void some_function() {
     32   usleep(100 + (rand() % 100));
     33 }
     34 
     35 int main() {
     36   BMARK(some_function);
     37 
     38   char percentiles[] = {
     39     10, 50, 90, 0
     40   };
     41 
     42   return bmark_run(10, percentiles);
     43 }
     44 ```
     45 
     46 Which in turn will output something similar to this:
     47 
     48 ```
     49 | Description   |      10 % |      50 % |      90 % |
     50 |:------------- | ---------:| ---------:| ---------:|
     51 | some_function | 163.00 us | 202.00 us | 245.00 us |
     52 ```
     53 
     54 API
     55 ---
     56 
     57 ```c
     58 BMARK(fn)
     59 ```
     60 
     61 Calls the `bmark_enqueue` method using the name of the function instead of a
     62 custom name.
     63 
     64 ```c
     65 void bmark_enqueue(char *name, void (*fn)());
     66 ```
     67 
     68 | Parameter   | Description                                       |
     69 | ----------- | ------------------------------------------------- |
     70 | name        | The displayed name of the row in the output table |
     71 | fn          | Function to call for making the time measurement  |
     72 
     73 Marks a method to be run as benchmark entry.
     74 
     75 ```c
     76 int bmark_run(int run_count, char percentiles[]);
     77 ```
     78 
     79 Runs the benchmarks, returns non-zero on library error.
     80 
     81 | Parameter   | Description                           |
     82 | ----------- | ------------------------------------- |
     83 | run_count   | How many times to run the methods for |
     84 | percentiles | Which percentiles of the runs to show |
     85 
     86 License
     87 -------
     88 
     89 benchmark source code is available under the MIT license.