I wrote a program in C ++ and trying to take the time to fully execute
int main (int argc, char ** argv) {clock_t tStart = clock (); // Your program is doing the work here printf ("taken time:% .2fs \ n", (double) (clock () - tStart) / CLOCKS_PER_SEC; Return 0; }
My problem is that it will always print 0.00s for execution time. Could this be due to using multiple pathabes in my program (my program uses pthread_join to ensure that all the threads have been executed, so I do not think this should be a problem) ?
Edit: // do the program's work = ...
for (i = 0; i <4; i ++) {err = Pthread_create (and threads [i], NULL, print, NULL); Pthread_join (thread [i], NULL); } Zero * Print (Zero * Data) {printf ("Hello world"); << code>
printf ("taken:% .2fs \ n" , (Double) (clock () - teestrate) / CLOCKS_PER_SEC);
All your three arithmetic operand are integers, so you divide the integer and get the 0
.
LHS or RHS symbolizes the /
symbol for a floating-point type and run your code more often! Your Benchmark is useless if it only measures a single run (which you have not got 0
, 1
) or 300
or something else Since it is very clear).
No comments:
Post a Comment