anyone can help me??
How to evaluate time between 2 event!!
anyone can help me??
How to evaluate time between 2 event!!
thanks !! I'll try!!!
^.^
P/s can you tell me the types of var1 and var 2?? (int/ double/ or others??)
Can you explain clearly!! T.T I don't understand!! (
And time in here count by second or other??
Last edited by nghoanglinh223; 04-02-2008 at 08:05 AM.
Can you explain if I use types clock_t for var1 and var2 .... they'll counted by second or other,wont' they??
And what's the difference between clock_t and MSDN??
Thanks you!
The time is not seconds, but "ticks", and there is #define constant in clock.h called CLOCKS_PER_SEC, which you can divide the result by to give you seconds. If you are measuring relatively short times, you should probably also convert your time to float or double.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
The function returns some sort of "ticks," that is defined by a special define somewhere.
clock_t is a type which clock() returns, simply put. You should use that type to ensure the code works.
clock_t is a type and MSDN is a place on the web for documentation about programming.And what's the difference between clock_t and MSDN??
MSDN is "MicoSoft Developers Network", and "clock_t" is the type that clock() returns as per the ANSI C89/ISO C90 standard (and earlier pseudo-standards).
So to compare those is like comparing an apple to a car - they don't compare very well, because they have completely different purpose and meaning.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Can you give me a example,plz!! ^.^
I have tried in this code:
int var1,var2,diff;
var1 = CLOCKS_PER_SEC;
ab.saveToFile("ATM.txt",key);
var2= CLOCKS_PER_SEC;
cout << " :" << var2;
diff = var2-var1;
cout << endl<<diff <<endl;
and the result is var1 = 1000;
var 2 =1000
diff = 0 :|
And i can't include clock.h
Thanks!!
Hello? You are supposed to call clock(). And we already told you the type is clock_t.
It's supposedly residing in time.h.Code:clock_t var1,var2,diff; var1 = clock(); ab.saveToFile("ATM.txt",key); var2 = clock(); cout << " :" << var2; diff = var2-var1; cout << endl<<diff / CLOCKS_PER_SEC <<endl;
The documentation also explicitly states
(elapsed time in seconds times CLOCKS_PER_SEC)
Yes, you should use var1= clock() and var2 = clock(), then DIVIDE the resulting difference by CLOCKS_PER_SEC().
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Thanks you so much!!
I would skip clock() and go for gettimeofday() if I were you. clock() is kind of not portable. It is defined everywhere (as far as I can tell), but have different meanings. IIRC on GCC/Windows, it measures the wall time (real time), on GCC/Linux, it measures CPU time (sometimes significantly less than real time).
Or, if you only need second precision, there is always time().