For Linux, play with this:

#ifndef WIN32

/// High resolution timers for Linux.


        #define NSEC_PER_SEC 1000000000LL

        inline uint64_t timespec_to_ns(const struct timespec *ts)
        {
                return ((uint64_t) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec;
        }

        /// Returns nanoseconds since epoch.
        inline uint64_t currentTimeNanoSec()
        {
                struct timespec timestamp_ts;
                //clock_gettime(CLOCK_MONOTONIC, &timestamp_ts);
                clock_gettime(CLOCK_REALTIME, &timestamp_ts);
                return timespec_to_ns(&timestamp_ts);
        }

        inline uint64_t clockResNanoSec()
        {
                struct timespec timestamp_ts;
                //clock_getres(CLOCK_MONOTONIC, &timestamp_ts);
                clock_getres(CLOCK_REALTIME, &timestamp_ts);
                return timespec_to_ns(&timestamp_ts);
        }

        #if 0
        int main(void)
        {
                printf("%lld, %lld\n", currentTimeNanoSec(), clockResNanoSec());
                printf("%lld, %lld\n", currentTimeNanoSec(), clockResNanoSec());
        }
        #endif
#else

Paul Melis wrote:
Paul Melis wrote:
J.P. Delport wrote:
In OSG you could do something like:

osg::Timer *globalHighResTimer=osg::Timer::instance();
uint64_t currentTimeNanoSec()
    {
        osg::Timer_t timer_t=globalHighResTimer->tick();
return (uint64_t)(timer_t * globalHighResTimer->getSecondsPerTick() * 1000000000);//timerTick * secondsPerTick * secondsToNanoSeconds
    }
This is win32-specific code right? There's no way you're going to get nanosecond precision on e.g. Linux where gettimeofday() is used by osg::Timer.
Ok ok, it would give valid results on non-windows, but give a false sense of nanosecond precision. And the OP needed only milliseconds...

Paul
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks Transtec Computers for their support.

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to