what function/header files do you use to return the current time in milliseconds?
i thought there was something like java's currentTimeMillis() function, but i can no longer remember
please help.. thanks
what function/header files do you use to return the current time in milliseconds?
i thought there was something like java's currentTimeMillis() function, but i can no longer remember
please help.. thanks
Depends which OS you're on.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Are you trying to benchmark something?
If so, then use the ASM 586 instruction RDTSC to get the current number of clock ticks.
no im doing an open gl program. trying to do the spinning triangle program. but the problem with that is, on faster systems, it spins really fast. i need a portable way to see how many milliseconds have passed so that it can spin a certain distance. but the problem is, the only standard is with seconds, which does me no good. is there any other solution to this?
Nice, but you still didn't mention the OS/Compiler.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I have written a function to use on my Linux systems... Not sure if it would help
this will return time in terms of seconds.. but it also gives out fractions like 1.23 seconds etc... when first called it starts off from 0.... You might need to include appropriate header files..Code:double Clock() { struct timeb t; ftime(&t); static unsigned int num=0; static int flag=0; if(flag==0){ num=t.time; flag=1; } double sec=t.time-num+(t.millitm/1000.0); return sec; }
#include <ctime>what function/header files...
clock() will return the number of "counts" (since your program started).
CLOCKS_PER_SEC is a system-specific constant for the number of "counts" per second. CLOCKS_PER_SEC is often equal to 1000, which means that clock() is already in milliseconds! But, don't count on that... write good (portable) code!
There is some information in the Programming FAQ.
Be aware of a "gotcha" with Windows: clock() will count in milliseconds, but the time_t structure is NOT updated every-single-millisecond by the OS. It jumps in...oh, I forget... something like 30 ms steps. There are other functions (in <windows>) that are more accurate... I think... GetClockTick() ...maybe GetClockCount() ???
microsoft compiler/gcc compiler in windows xp
but this program will be compiled with gcc on windows xp, osx and linux
>>maybe GetClockCount() ???
GetTickCount()
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Originally Posted by Hunter2
thats defined in windows.h
which i cant use
Well, can't think of any standard way of doing it assuming dougdbug is correct about 30ms jumps. I would have suggested QueryPerformanceCounter(), but that's Windows specific too. But heck, if you're doing OpenGL on Windows, why can't you use windows.h?
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Here it goes...
CLOCK
Syntax
#include <time.h>
clock_t clock(void);
Description
This function returns the number of clock ticks since an arbitrary time, actually, since the first call to clock, which itself returns zero. The number of tics per second is CLOCKS_PER_SEC.
Return Value
The number of tics.
Portability
ANSI, POSIX
Example
printf("%d seconds have elapsed\n", clock()/CLOCKS_PER_SEC);
SLEEP
Syntax
#include <unistd.h>
unsigned sleep(unsigned seconds);
Description
This function causes the program to pause for seconds seconds.
Return Value
The number of seconds that haven't passed (i.e. always zero)
Portability
not ANSI, POSIX
Example
sleep(5);
> but this program will be compiled with gcc on windows xp, osx and linux
Tough on you - there is no standard function which returns milliseconds on all these platforms.
So somewhere you're going to have to do something like
Code:#if defined(WINDOWS) #include <windows.h> int myGetMilliseconds ( void ) { return GetTickCount(); } #elif defined(LINUX) int myGetMilliseconds ( void ) { // find some suitable function } #else #error specify an OS with -DNAME_OF_OS #endif
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
thanks, but the clock function will more than due.Originally Posted by Salem
i just needed a value returned that was small enough so that it would be about the same on any system to control motion in opengl