c++ - How to Measure How Many Results App Can Produce Per Second -
i have 1 c++ app called idcreator takes 2 arguments produce ids. prints return value stdout ---- using printf ---- calling process fetches.
now, wonder how many ids idcreator able produce per second (must done outside application), how can achieve this? is below code proper doing such job? there other way?
string getid; getid.append("./idcreator arg1 arg2"); int count = 0; const int period = 100; const int len = 512; char buff[len] = {0}; time_t tick1 = time(null); while(1) { time_t tick2 = time(null); if ((tick2 - tick1) > period) break; file* res = popen(cmd.c_str(), "r"); if (res) { fgets(res, buff, sizeof(buf)); pclose(res); count++; } } printf("products per second is: %d", count/period);
instead of creating function indepedently measure function time , doing fancy/complex stuff, suggest simple way.
add logger/timers @ start , end of id generation module like,
do
logger.info(time)
{ id generation }
logger.info(time)
do something
loggers example purpose(generally easiest way achieve timestamps) find time required generate 1 id based on hope time in millis/micros (if in micro need use timers microsecond granularity).
if need x milliseconds generate 1 id generate round(1000/x) id's in second. it's simple equation.
- you can add loggers @ start , end of program , limit program execute fix time duration (use logical breaking using timers or manual stop of program)
if in x seconds program generates y ids then, in 1 seconds program generates y/x ids
run program 2-3 times enough long duration have average , accuracy throughput of program.
i hope helpful.
Comments
Post a Comment