Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Classify clock() for variables of type clock_t

Reply
Thread Tools

Classify clock() for variables of type clock_t

 
 
clusardi2k@aol.com
Guest
Posts: n/a
 
      07-12-2013
Hello,

I was recently notified that I can not use "clock()" even though it works fairly well on my computer!

Question: Based on this information, how can I identify other functions that I am not allowed to use?

Thanks,
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      07-12-2013
On 7/12/2013 9:12 AM, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I was recently notified that I can not use "clock()" even though it

works fairly well on my computer!

"Notified"? By whom or by what?

> Question: Based on this information, how can I identify other

functions that I am not allowed to use?

I suppose the only way to "identify other functions" is to tap the same
source of information. Whoever "notified" you that you "can not use"
function 'clock' should be able to supply you with the list of other
functions you "can not use" (whatever that means in your circumstances).

V
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
 
 
 
James Kanze
Guest
Posts: n/a
 
      07-12-2013
On Friday, July 12, 2013 2:41:03 PM UTC+1, Paavo Helde wrote:
> (E-Mail Removed) wrote in
> news:(E-Mail Removed):


> > I was recently notified that I can not use "clock()" even though it
> > works fairly well on my computer!


> > Question: Based on this information, how can I identify other
> > functions that I am not allowed to use?


> It might help if there were any rationale why you cannot use clock(). For
> example, if your evil overlord does not like words beginning with c, then
> you cannot use chdir(), copy_backward() etc.


> As I understand you have absolutely no idea why clock() was banned In
> this case I'm afraid we can't help you either.


The only reason I can think of is that it doesn't work in VC++.
Otherwise: I can't think of any reason you would want to use it
in released software anyway. In fact, about the only place
I would expect to see it is in a benchmarking harness. (One
might insert it temporarily for some quick timings in situ in
the application, but in that case, you'd certainly remove it
before delivery.)

--
James
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      07-12-2013
On 7/12/2013 9:48 AM, James Kanze wrote:
> On Friday, July 12, 2013 2:41:03 PM UTC+1, Paavo Helde wrote:
>> (E-Mail Removed) wrote in
>> news:(E-Mail Removed):

>
>>> I was recently notified that I can not use "clock()" even though it
>>> works fairly well on my computer!

>
>>> Question: Based on this information, how can I identify other
>>> functions that I am not allowed to use?

>
>> It might help if there were any rationale why you cannot use clock(). For
>> example, if your evil overlord does not like words beginning with c, then
>> you cannot use chdir(), copy_backward() etc.

>
>> As I understand you have absolutely no idea why clock() was banned In
>> this case I'm afraid we can't help you either.

>
> The only reason I can think of is that it doesn't work in VC++.


It doesn't? 8-O

Care to elaborate?

> [..]


V
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
clusardi2k@aol.com
Guest
Posts: n/a
 
      07-12-2013
On Friday, July 12, 2013 9:48:57 AM UTC-4, James Kanze wrote:
> On Friday, July 12, 2013 2:41:03 PM UTC+1, Paavo Helde wrote:
> It might help if there were any rationale why you cannot use clock(). For>
> example, if your evil overlord does not like words beginning with c, then>
> you cannot use chdir(), copy_backward() etc. > As I understand you have
> absolutely no idea why clock() was banned In > this case I'm afraid we
> can't help you either. The only reason I can think of is that it doesn't work
> in VC++. Otherwise: I can't think of any reason you would want to use it in
> released software anyway. In fact, about the only place I would expect tosee
> it is in a benchmarking harness. (One might insert it temporarily for some
> quick timings in situ in the application, but in that case, you'd certainly
> remove it before delivery.) -- James


One reason that I was told was that it's based on program execution time and not system time. Someone, who has a lot of programming experience, latertold me "clock()" won't work on all computers. I think the second person was trying to make me feel better and was too busy to give me better reasoning.

The reason the problem came up was I noticed that using "clock ()" would generate larger and larger errors each time a routine was called. After the error reached nearly one second, the error would drop down to just above zero and repeat its building up. My feelings were that during this one second period my code would increasonly do other things. So, at the start of the one second my code would do a little, but near the end of the one second it would be doing a lot more.

What do you think? Should I used variables of type "SYSTEMTIME" instead. Doing math with "SYSTEMTIME" variables is harder etc.

Thanks,
 
Reply With Quote
 
clusa@aol.com
Guest
Posts: n/a
 
      07-12-2013
> On Friday, July 12, 2013 10:30:11 AM UTC-4, Paavo Helde wrote:

> And what do you mean by "clock() generates errors"? Do you mean it returns an
> error code (clock_t(-1))?


Sorry, I meant to say that when a routine containing "clock()" gets called the clock count becomes later and later. Basically, I was expecting my routine to be called at a specific time, but during one second intervals the routine was getting called later and later. So, the amount of time between the expected call time and the actual arrival of the call I was calling an error.

"clock()" was not returning an error code.
 
Reply With Quote
 
clusardi2k@aol.com
Guest
Posts: n/a
 
      07-12-2013
> On Friday, July 12, 2013 10:48:53 AM UTC-4, Drew Lawson wrote:
> Perhaps things would be clearer if you stated what you are trying to use clock
>() for.


I did not write the original code. It has always worked fine. I'm just adding code to it. When I try to add "clock()" to the code, it's the very first change that I've made to it.

So, I use "clock()" for this:

(1) I do the following in a routine, call it r1.
(2) When "clock()" returns a value greater or equal to t2 (see t2 below), I do the following:
(2) I first call "clock()" and save it to a variable, call it t1.
(3) I add a time span (of 30 seconds) to t1, (call the time span ts1). The resulting addition is saved to a variable, call it t2. The code looks "something" like this:
t2 = t1 + ((float)CLOCKS_PER_SEC * 30.3).
(4) The code goes off and does other things, but eventually arrives at step (1) again.
 
Reply With Quote
 
clusardi2k@aol.com
Guest
Posts: n/a
 
      07-12-2013
> On Friday, July 12, 2013 10:52:26 AM UTC-4, Paavo Helde wrote:
> And so you came to the conclusion that the problem must be with clock() as your
> code is certainly correct? Hilarious! p


No, I want to use "clock()", but two different people told me that I cannot (see above).



 
Reply With Quote
 
clusardi2k@aol.com
Guest
Posts: n/a
 
      07-12-2013
> On Friday, July 12, 2013 10:48:53 AM UTC-4, Drew Lawson wrote:
> Perhaps things would be clearer if you stated what you are trying to use clock
>() for.


I did not write the original code. It has always worked fine. I'm just adding code to it. When I try to add "clock()" to the code, it's the very first change that I've made to it.

So, I use "clock()" for this:

(1) I do the following in a routine, call it r1.
(2) When "clock()" returns a value greater or equal to t2 (see t2 below), I do the following:
(2) I first call "clock()" and save it to a variable, call it t1.
(3) I add a time span (of 30.3 seconds) to t1, (call the time span ts1). The resulting addition is saved to a variable, call it t2. The code looks "something" like this:
t2 = t1 + ((float)CLOCKS_PER_SEC * 30.3).
(4) The code goes off and does other things, but eventually arrives at step (1) again.
 
Reply With Quote
 
clusardi2k@aol.com
Guest
Posts: n/a
 
      07-12-2013
> On Friday, July 12, 2013 10:48:53 AM UTC-4, Drew Lawson wrote:
> Perhaps things would be clearer if you stated what you are trying to use clock
>() for.


I did not write the original code. It has always worked fine. I'm just adding code to it. When I try to add "clock()" to the code, it's the very firstchange that I've made to it.

So, I use "clock()" for this:

(1) I do the following in a routine, call it r1.
(2) When "clock()" returns a value greater or equal to t2 (see t2 below), Ido the following:
(3) I first call "clock()" and save it to a variable, call it t1.
(4) I add a time span (of 30.3 seconds) to t1, (call the time span ts1). The resulting addition is saved to a variable, call it t2.
(5) I computer a lateness variable, call it late1. late1 is a computation of the actual arrival time minus expected time of arrival.

Via from memory, the code looks "something" like this:

#include time.h

clock_t t1, t2, ts1;

ts1 = (float)CLOCKS_PER_SEC * 30.3;

t1 = clock ();

if ( t3 >= t2 )
{
late1 = t3 - t2;
t2 = t1 + ts1 + late1;
}

(6) The code goes off and does other things, but eventually arrives at step(1) again.

Note: Obviously, late1 is not absolutely accurate because each instruction adds time, but the above code (in the "if") is almost exactly as I coded it.. So, late1 repeatedly and slowly increases from small values near zero to about one second. late1 is what I earlier called error.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: "Why is it necessary to classify data according to its type incomputer programming?" tm C Programming 7 07-11-2010 10:10 PM
Re: How to classify RDP traffic? Mr. Nobody Cisco 0 07-12-2008 04:00 PM
Re: QoS: How to classify RDP traffic? Bod43@hotmail.co.uk Cisco 0 07-12-2008 10:08 AM
clock_t clock() ambiguity Matt C++ 30 08-01-2006 11:16 PM
how to print clock_t variables? ykz C Programming 4 11-03-2003 04:53 PM



Advertisments