how to calculate time difference in milliseconds in C/C++
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Well I suppose the question is:
How do you suppose we represent a negative number in an unsigned int?
In reflection both codes return a value which indicates if the value is positive or negative, which I failed to notice in your code sample.
I stand corrected.
Now that you've got these cool routines (and they *are* cool!) ... please be sure to take the results with a pound of salt (or better, to quote Andrew Tanenbaum, with a "metric ton of salt").
Results are seldom accurate to-the-millisecond, much less to the microsecond. At the very least, you'll definitely want to run multiple tests, and average your results...
Now that you've got these cool routines (and they *are* cool!) ... please be sure to take the results with a pound of salt (or better, to quote Andrew Tanenbaum, with a "metric ton of salt").
I don't understand why the other functions posted are so complicated. It can be done in a single long line.
You're right, it can. But the reason the other functions are that way is not because waqasdaar needed the extra complication (he didn't), but because of the history of the thread. jiml8 posted something that worked for him, which returned the difference as a struct timeval. I changed it somewhat so it returned both a struct timeval and a long long.
The code kinda changed incrementally. Or, as one of my past cow-orkers was known to say, "excrementally".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.