Hi,
I am looking for a function or any example that shows elapsed time in seconds and minutes. I didnt find any solution for both OS Win and Linux. I am looking for example that works for both - win and linux.
Thank You in advance!
Hi,
I am looking for a function or any example that shows elapsed time in seconds and minutes. I didnt find any solution for both OS Win and Linux. I am looking for example that works for both - win and linux.
Thank You in advance!
You should look into the <ctime> header, it probably has what you need.
How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.
Most of what it does is for measuring time spans in seconds and fractions thereof.
for what the OP needs, it's probably perfectly adequate.
I don't really understand why the standards committee didn't add a proper datetime class with arithmetic, comparison, and istream/ostream operators. it seems like they essentially expect us to continue to use the legacy C library functions for arithmetic, comparison, parsing and formatting operations. even if the datetime class used the legacy C stuff behind the scenes, it would still be better to have a modern, more C++-like way of handling datetime values. also fixed-point decimal types, but that's a topic for a different discussion.
Probably because if they had had to reach an agreement on that too we'd be looking at C++15 instead of C++11.
Yeah, I don't know either.
Boost might be simpler, though. Here's a perfectly good example of something like the OP wants to do: Examples - 1.53.0
I made this. What do You think guys?
it starts counting when user enter enything.
Code:#include <iostream> #include <ctime> #include <cmath> using namespace std; int main(){ clock_t t; int f; t = clock(); f = laiks (99999); t = clock() - t; cout<<"You were playing " <<((float)t)/CLOCKS_PER_SEC*100<<" seconds."<< endl; return 0; } int laiks (int n) { int i,j,freq=0; int sec=n-1; for (i=2; i<=n; ++i) for (j=sqrt(i);j>1;--j) if (i%j==0) { --freq; break; } return sec; }
Last edited by Solarwin; 03-14-2013 at 11:09 AM. Reason: Elysia
Why are you multiplying the time by 100?
You can multiply it by 1000 and indicate the time is in milliseconds.
How do you know it's not the right result?
You must have some fast fingers
Here's the output from my IDE console window after removing the multiplication by 100:
And changing the argument passed to "laiks()" from 99999 to 999999:Code:You were playing 0.232 seconds. Process returned 0 (0x0) execution time : 0.278 s Press any key to continue.
Code:You were playing 7.312 seconds. Process returned 0 (0x0) execution time : 7.390 s Press any key to continue.
what I don't like about boost is that it doesn't have a combined datetime. it handles dates as a separate type from times. how do you do datetime arithmetic and comparisons, to second precision, without the date and time being held in the same value? boost's implementation is effectively useless to me.
I don't know. It seems that date is a subset of time, so if you work with time, you work with dates.
See example: Examples - 1.53.0