clock_gettime() help

OK. First time back on here in a few years. Long story short, I need some assistance trying to wrap my head around the clock_gettime() function.
Also, this is for a college coarse assignment. Please DO NOT post anything that could POSSIBLY break the AMC code of ethics, in regards to all of its guidelines.

The assignment in question is this:

The user inputs a number tat is to be searched for in a sorted vector. We are to time the std:find and std::lower_bound searching algorithms that we are required to utilize. The issue that I am having with this is not this part but rather how to use the clock_gettime() function calls.

Any and all help with this issue will be and is GREATLY appriciated.

I need a clean, clear-cut explanation of each method that needs to be used to time a specific block of code. (ex. std::binary_search, std::find, etc...) Now, don't misunderstand what I want. What I DON'T want is to be told HOW to implement my code but rather what each method does and WHY. I will give a format and hopefully it will make responding to this so easy that it won't take more than 10 minutes of your time. This is the webpage that I am using to "try" to understand how to implement the clock_gettime() function call. Call me crazy but I think that its made very poorly and is in dire need of an overhaul to the presentation of the information. (Disclaimer: Personal Opinion...)

URL: http://linux.die.net/man/3/clock_gettime

Lets begin:
=========================================================
=========================================================
CLOCK_PROCESS_CPUTIME_ID:
-------------------------

What is the "type" for this constant?
-------------------------------------
(And yes, I'm being serious. The error I'm getting is telling me it require a type def or something along those lines...)

Answer: //your answer goes here...

How is it supposed to be GENERICALLY implemented?
-------------------------------------------------

//Example goes here...



=============================================================================
=============================================================================

Timespec Object (as defined in <ctime> (if it even is...):
----------------------------------------------------------

How do I construct one?
-----------------------
Answer: //your answer goes here...

How is it supposed to be GENERICALLY implemented?
-------------------------------------------------

//Example goes here...


=============================================================================
=============================================================================
clock_gettime():
----------------
I am under the assumption that you would set the start() and stop() method calls that we are required to use to gather the required times to calculate the total elapsed time, via the allotted function call, so that I can then output the result to the appropriate stream.

(The method name that I am using here is just a placeholder as not to show the same code that I am using, if only because I, again, just want to have a better understanding.)

Such as (example below):

startclock()
{

m_start = clock_gettime();

}


(Is this anywhere close? If not, please proceed to answer in the field below.)

Answer: //your answer goes here...

How is it supposed to be GENERICALLY implemented?
-------------------------------------------------

//Example goes here...



Again, thank you for any help that you would possibly be able to show me in regards to this program. Thanks a bunch and I hope that all of you have a good day. ttyl.

Regards,

Butterfreedom
(aka. TheFemaleMagusOfDalaran and Nerdrage23)






Call me crazy but I think that its made very poorly and is in dire need of an overhaul

That's just (some version of) the Linux documentation. You can also consult the POSIX documentation at http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getres.html

What is the "type" for this constant?

It is clockid_t or a type convertible to clockid_t, defined in <time.h> (on POSIX systems, since this is not a C or C++ type)

Timespec Object (as defined in <ctime> (if it even is...):
timespec is a type, it is defined in <time.h> (on POSIX systems, again)

How do I construct one?

Same way as any other object, for example
timespec ts; // constructs an object called 'ts' of type 'timespec'

I am not sure what you mean by "GENERICALLY implemented" in either case.

Is this anywhere close?

Given some assumptions about the code it could be part of (that is, assuming you've decided to create some sort of a time keeping class), yes.
Last edited on
OMG thank you SOOOOO much, Cubbi! This is EXACTLY what I am looking for! And not a moment toooo soon! I have less than 6 hours before class and, with this, I might actually be able to take a nap before I go! How do I give you a +1 (if this site does ratings for its users?). If this works the way I believe it does, I think that I will have pretty much surpassed my understanding of this from the prior semesters! Again, you have my never ending thanks!

Sincerely,

Butterfreedom

(aka. TheFemaleMagusofDalaran and/or Nerdrage23)

(PS. If this forum has a "+1" rating system, tell me how to give you one because you pretty much just saved my butt! Again, (again...) thanks!)
If you still here, Cubbi, I was wondering if you might be able to give me some syntactical assistance? At the moment, while I understand how to get it to work from a logical stand-point, I am now hitting errors that I would like to have resolved before I proceed. I can GUARENTEE that they are very small and stupid like a missed data type somewhere or a character missing from a variable name. The issue with me finding them is that I have to use the cmd prompt to fix them because it will assist me when I proceed into the industry, if only to have a better understanding of how the underlining structure of coding works. (If that makes ANY sense...?)

Provided that you see this before 1:30, it would be greatly appreciated if you wouldn't mind looking over a few blocks of code if only to make sure I have things syntactically done right. That is now my biggest road block...
Topic archived. No new replies allowed.