#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" ;
}
I2luY2x1ZGUgPGN0aW1lPgojaW5jbHVkZSA8Y3N0ZGxpYj4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKaW50IGZuKCkKewogICAgaW50IHIgPSAwIDsKICAgIGZvciggaW50IGkgPSAwIDsgaSA8IDEwMDAgOyArK2kgKSByICs9IHN0ZDo6cmFuZCgpICUgMiA7CiAgICByZXR1cm4gciA7Cn0KCmludCBtYWluKCkKewogICAgLy8gZ2V0IGFuIGVzdGltYXRlIG9mIHRoZSBwcm9jZXNzb3IgdGltZSB1c2VkCiAgICBhdXRvIHN0YXJ0ID0gc3RkOjpjbG9jaygpIDsKCiAgICAvLyBvcGVyYXRpb24gdG8gdGltZQogICAgc3RhdGljIHZvbGF0aWxlIGludCB2ID0gMCA7CiAgICBjb25zdGV4cHIgaW50IE4gPSAxMDAwIDsKICAgIGZvciggaW50IGkgPSAwIDsgaSA8IE4gOyArK2kgKSB2ICs9IGZuKCkgOwoKICAgIGNvbnN0IGRvdWJsZSBlbGFwc2VkID0gc3RkOjpjbG9jaygpIC0gc3RhcnQgOwogICAgc3RkOjpjb3V0IDw8ICJhcHByb3hpbWF0ZSBwcm9jZXNzb3IgdGltZSBmb3IgYSBzaW5nbGUgY2FsbCBvZiBmbjogIgogICAgICAgICAgICAgICA8PCAoZWxhcHNlZCoxMDAwMDAwKSAvIChDTE9DS1NfUEVSX1NFQypOKQogICAgICAgICAgICAgICA8PCAiIG1pY3Jvc2Vjb25kc1xuIiA7Cn0K