#include <ctime>
#include <cstdlib>
#include <iostream>

int fn()
{
    int r = 0 ;
    for( int i = 0 ; i < 1000 ; ++i ) r += std::rand() % 2 ;
    return r ;
}

int main()
{
    // get an estimate of the processor time used
    auto start = std::clock() ;

    // operation to time
    static volatile int v = 0 ;
    constexpr int N = 1000 ;
    for( int i = 0 ; i < N ; ++i ) v += fn() ;

    const double elapsed = std::clock() - start ;
    std::cout << "approximate processor time for a single call of fn: "
               << (elapsed*1000000) / (CLOCKS_PER_SEC*N)
               << " microseconds\n" ;
}
