Hiding getting elapsed time in C -


i need hide instructions elapsed time in c. example in next code there several line instructions elapsed time of function foo.

struct timeval start_keygen, end_keygen; long int diff_keygen_sec = 0; gettimeofday(&start_keygen, null); foo(r, w, h); gettimeofday(&end_keygen, null); timediff(start_keygen, end_keygen, &diff_keygen_sec);  

my question how hide several lines in 1 function, example in "gettime", i.e:

gettime(foo(r,w,h)) 

you use macro:

#define time(e, res) do{struct timeval start_keygen, end_keygen; \             res = 0; \             gettimeofday(&start_keygen, null); \             e; \             gettimeofday(&end_keygen, null); \             timediff(start_keygen, end_keygen, &res)} while(0)  \ 

then can do:

long int myres; time(foo(r,w,h), myres); 

this expand code have, each time used @ compile time , bind result myres.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -