Helper utilities for easier benchmarking in C I have this tiny library for measuring the execution time in milliseconds and returning the duration plus the result:

execres.h

/******************
* File: execres.h *
******************/

#ifndef EXECRES_H
#define EXECRES_H

#include &lt;sys/time.h&gt;

typedef struct {
    unsigned long long  millis;
    void*               result;
} ExecResult, *PExecResult;

PExecResult execTime(void* (*code)(void*), void* param);

#endif  /* EXECRES_H */


execres.c

/******************
* File: execres.c *
******************/

#include "execres.h"
#include &lt;stdlib.h&gt;

PExecResult execTime(void* (*code)(void*), void* param)
{
    PExecResult result;
    struct timeval tva;
    struct timeval tvb;

    if (!code)
    {
        return NULL;
    }

    result = malloc(sizeof(ExecResult));

    if (!result)
    {
        return NULL;
    }

    gettimeofday(&amp;tva, NULL);
    result-&gt;result = code(param);
    gettimeofday(&amp;tvb, NULL);

    result-&gt;millis = (unsigned long long)
                     (tvb.tv_sec * 1000 + tvb.tv_usec / 1000 -
                      tva.tv_sec * 1000 - tva.tv_usec / 1000);
    return result;
}


main.c

/***************
* File: main.c *
***************/

#include &lt;stdint.h&gt;
#include &lt;stdio.h&gt;
#include "execres.h"

static uint64_t Fibonacci(uint64_t n)
{
    switch (n)
    {
        case 0:
            return 0;

        case 1:
            return 1;

        default:
            return Fibonacci(n - 1) + Fibonacci(n - 2);
    }
}

int main()
{
    PExecResult result;

    puts("Begin computation.");

    result = execTime((void* (*)(void*)) Fibonacci, (void*) 40);

    printf("Fibonacci took %u milliseconds and returned %llu.\n",
           (unsigned) result-&gt;millis,
           (uint64_t) result-&gt;result);

    return 0;
}
Nice bit of code!  Here are a few suggestions:


Initialize your variables when you declare them.  This helps shorten the code a bit and reduce possible bugs.
You need documenting comments within your code.  Especially since you are considering this as a library.
I would remove the NULL check on code in your execTime method, and document that a valid function pointer should be passed in.  I would expect the code to break if I tried to time NULL, not NULL to be returned back.  The standard library does this same thing with a few of their functions, like strlen().
Good job checking the return from malloc().
I would use the C11 standard function timespec_get() for your timing code.  It's a C standard (important!) function that has nanosecond precision.
If you want a better Fibonacci algorithm, here is an answer I wrote up a while ago on it.
Good job using puts() in place of printf() when you can.
You don't have to return 0 at the end of main(). The C standard  knows how frequently this is used, and lets us omit it.


  C99 &amp; C11 §5.1.2.2(3)
  
  ...reaching the } that terminates the main() function returns a
  value of 0.