mardi 14 juin 2022

Best way to design a time-measuring structure in C++?

I am struggling to do the following in the best way possible:

I have to measure the execution time of a C++ functionality implemented in C++. I have access to the code, so I can extend/modify it. The structure of what I have to do would be something like:

for (int k=0;k<nbatches;k++) {
   //Set parameters from config file
   parameters=readFromFile(k);
   s=startTime();
   for(int i=0;i<niters;i++)
   {
       o=namespacefoo::foo(parameters);
       writeToFile(o,i,k);
   }
   e=endTime();
   times[k]=e-s/niters;
}
return times;

I am quite sure that I will have to use the same structure to measure other functionalities from other namespaces.

I am not sure if it makes sense to transform each functionality into a derived-class from a base-class. Each derived-class would implement the virtual read/write wrappers and there would be a measuring function, non-member non-friend convenience function, which would implement my previous structures. Also, the number/type of the parameters is also dependent on each derived-class. Maybe I would have to do the same derived-class strategy for the parameters too. Finally a factory function would set everything.

Does this seem very cumbersome for the simple task I want to solve? I am sure this is not the first time that someone needs something like this and I do not want to rediscover the wheel.

Thanks

Aucun commentaire:

Enregistrer un commentaire