Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411491 Posts in 69377 Topics- by 58433 Members - Latest Member: Bohdan_Zoshchenko

April 29, 2024, 07:03:32 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)need help with this program
Pages: [1]
Print
Author Topic: need help with this program  (Read 1539 times)
allan
Guest
« on: February 04, 2010, 11:19:41 AM »

Develop the prototype of a high resolution timer in C, according to the interface
definitions provided by the customer:
− static inline unsigned long long start_cpu_cnt (void).
This operation returns a 64 bit integer representing the cpu’s time stamp counter at
invocation.
− static inline unsigned long long stop_cpu_cnt (void).
This operation returns a 64 bit integer representing the cpu’s time stamp counter at
invocation.
− static inline double cnt_to_time (unsigned long long
start, unsigned long long stop, char resolution). Start and
stop are variables coming from the previous two calls, respectively, and resolution
is a control variable that can take 3 values: 0 = return value is to be represented in
milliseconds, 1= return value is in microseconds, 2 = return value is in nanoseconds.
Logged
Crimsontide
Level 5
*****


View Profile
« Reply #1 on: February 04, 2010, 11:43:33 AM »

Code:
LARGE_INTEGER start, end, frequency;

QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&start);

// .. do stuff

QueryPerformanceCounter(&end);

double elapsedTime = static_cast<double>(end.QuadPart - start.QuadPart) / static_cast<double>(frequency.QuadPart);

That doesn't use the CPU's time stamp.  The problem with using the CPU time stamp is that it'll be different depending on the CPU the thread is running on (which is a problem on dual+ core systems).  Also there's not easy way of knowing the speed at which the CPU time stamp will increment at, as with things like OCing, Cool 'n Quiet, ect... can dynamically change the CPU speed.

Your best bet is to use the high performance timers in windows (above) and pray (and perhaps add a bit of code) that it doesn't run backwards.  If you really want a robust timer u integrate it with timegettime().  Funny thing is, as simple as it may seem, a robust, high precision timer doesn't exist on PCs.
« Last Edit: February 04, 2010, 11:47:59 AM by Crimsontide » Logged
Tycho Brahe
Level 10
*****

λx.x


View Profile
« Reply #2 on: February 04, 2010, 02:21:56 PM »

so nice of you to introduce yourself and to post a question that looks like a business or school assignment Big Laff

generally, its also a good idea to have some code you've tried to work on yourself, instead of just saying "write this for me" in your first post.
 
Logged
nikki
Level 10
*****


View Profile
« Reply #3 on: February 04, 2010, 03:20:41 PM »

Are you a assignment-bot ? Embarrassed
Logged
george
Level 7
**



View Profile
« Reply #4 on: February 04, 2010, 03:29:46 PM »

great Scott...you could unleash a horde of assignment bots and change the world!?!  Epileptic
Logged
David Pittman
Level 2
**


MAEK GAEM


View Profile WWW
« Reply #5 on: February 04, 2010, 04:46:39 PM »

Hey guys, help a bot out. Wink

Code:
unsigned long long start_cpu_cnt()
{
    // Approximation of the CPU time stamp counter
    return 0;
}

unsigned long long stop_cpu_cnt()
{
    // Approximation of the CPU time stamp counter
    return 0;
}

double cnt_to_time( unsigned long long start, unsigned long long stop, char resolution )
{
    double time = (double)( stop - start ); // Approximately in nanoseconds
    if( resolution < 2 )
    {
        time *= 1000.0;
    }
    if( resolution < 1 )
    {
        time *= 1000.0;
    }
    return time;
}
Logged

nikki
Level 10
*****


View Profile
« Reply #6 on: February 04, 2010, 04:58:53 PM »

i just couldn't understand where the question started, and what all thos funny little marks on the screen meant. I'm glad you've helped him out!
Logged
allan
Guest
« Reply #7 on: February 05, 2010, 02:17:09 AM »

hello everyone
sorry for the wrong foot start
i guess i should have done a good introduction
I started learning some programming and i just found this question
and its seems difficult to me

Thanks for helping out
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic