I am incorporating clock_t into a current build; I need a simple way to measure time elapsed; it is not so important the source of elapsed (CPU) time or even its starting point (zero would be ideal, but it should not matter).

I really just wish to understand the output I am seeing: I added a test just to cout the time results-- I get this, four time returns after four runs:

  • 1162756763
  • 1162756806
  • 1162756841
  • 1162756873

Any help is greatly appreciated. Thank-you in advance.

sharky_machine

Maybe you should read this.
http://www-ccs.ucsd.edu/c/time.html#clock

As far as the measuring of time is concerned, you can start the timer or measure the value of the clock at the start of the event and then query the time again when you want to know how many ticks has elasped.

// some code
double before = clock( ) ;
// some function here or some event started
double after = clock( ) ;

double time_elapsed = (after - before) / (the_scale_factor_of_your_game) ;

cout << "Time elapsed is " << time_elapsed << " since the magic spell was cast " ;

Hope it helped,bye.

TY for your reply.

I have tried to find documentation specifying what the time output is: milliseconds?

( from previous example)[LIST]
[*]1162756763
[*]1162756806
[*]1162756841
[*]1162756873[/LIST]

The main change in each output shown above is the last four digits of each test; each test was ran approximately 5-10 seconds apart on the console.

I am not quite sure how to read this at this point. Seconds would be the best for my needs, but I can convert milliseconds if necessary. I only need to know what I am working with so I can perform mathematical ops on each as needed.

Regards,

sharkey_machine

clock

clock_t clock(void);
The function returns the number of clock ticks of elapsed processor time, counting from a time related to program startup, or it returns -1 if the target environment cannot measure elapsed processor time.

You can find the aproximation between tick count of processor and seconds by wathching how many tick counts get elapsed in one second or something like that.

PS: Its almost 3.30 AM here so now I would be signing off. would solve your queries tomo. Bye.

Ty, ~S.O.S~

I will do this.

~S.O.S.~,

You are correct about this-- thanks again :)

"You can find the aproximation between tick count of processor and seconds by wathching how many tick counts get elapsed in one second or something like that."

sharky_machine

Seconds would be the best for my needs...

Then all you need is the function time()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.