c - How to get the running of time of my program with gettimeofday() -


So I get time at the beginning of the code, run it, and then get time.

Structure deadlines start, end; Gettimeofday (and start, tap); // time for code gettimeofday (and end, tap); // Get the total number of MS which took the code: unsigned int t = end.tv_usec - begin.tv_usec;

Now I want to print "** 0.007 seconds to run the code" or print something like this.

Then two problems:

1) T contains the value of the order of 6000, and I know that the code did not take 6 seconds to run.

2) How can I change it in two, is this an unsigned int? Or is there an easy way to print the output the way I wanted it?

1) That's because usec is not 6000 milliseconds, it's 6000 Is Microsoft (6 milliseconds or 6-second one-thousandths).

2) Try this: (double) t / 1000000 it will convert to a double, and then the number of seconds instead of the number of microsoft to divide by one million. Find out.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -