clock

clock_gettime alternative in Mac OS X

浪尽此生 提交于 2019-11-26 05:55:18
问题 When compiling a program I wrote on Mac OS X after installing the necessary libraries through MacPorts, I get this error: In function \'nanotime\': error: \'CLOCK_REALTIME\' undeclared (first use in this function) error: (Each undeclared identifier is reported only once error: for each function it appears in.) It appears that clock_gettime is not implemented in Mac OS X. Is there an alternative means of getting the epoch time in nanoseconds ? Unfortunately gettimeofday is in microseconds .

What’s the correct way to use printf to print a clock_t?

ε祈祈猫儿з 提交于 2019-11-26 05:51:12
问题 I\'m currently using a explicit cast to unsigned long long and using %llu to print it, but since size_t has the %z specifier, why doesn\'t clock_t have one? There isn\'t even a macro for it. Maybe I can assume that on an x64 system (OS and CPU) size_t is 8 bytes in length (and even in this case, they have provided %z ), but what about clock_t ? 回答1: There seems to be no perfect way. The root of the problem is that clock_t can be either integer or floating point. clock_t can be a floating

Linux clock_gettime(CLOCK_MONOTONIC) strange non-monotonic behavior

巧了我就是萌 提交于 2019-11-26 05:30:48
问题 Folks, in my application I\'m using clock_gettime(CLOCK_MONOTONIC) in order to measure the delta time between frames (a typical approach in gamedev) and from time to time I\'m facing a strange behavior of clock_gettime(..) - returned values occasionally are not monotonic (i.e prev. time is bigger than current time). Currently, if such a paradox happens I simply skip the current frame and start processing the next one. The question is how can this be possible at all? Is it a bug in Linux POSIX

Intent to launch the clock application on android

隐身守侯 提交于 2019-11-26 05:27:43
问题 I am facing a problem with a clock widget i made. I want the user to touch the clock and launch the clock app on the phone. this is the code: //this worked on my nexus 2.1 if(VERSION.SDK.equals(\"7\")){ RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget); Intent AlarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(new ComponentName(\"com.android.deskclock\", \"com.android.deskclock.DeskClock\")); PendingIntent

Getting iOS system uptime, that doesn't pause when asleep

北城余情 提交于 2019-11-26 02:51:24
问题 I\'m looking for a way to get an absolute, always-incrementing system uptime on iOS. It should return the time since the device was last rebooted, and not be affected by changes to the system date. All the methods I can find either pause when the device is asleep ( CACurrentMediaTime , [NSProcessInfo systemUptime] , mach_absolute_time ) or are changed when the system date changes ( sysctl/KERN_BOOTTIME ). Any ideas? 回答1: I think I worked it out. time() carries on incrementing while the device

C++ obtaining milliseconds time on Linux — clock() doesn't seem to work properly

断了今生、忘了曾经 提交于 2019-11-26 02:05:32
问题 On Windows, clock() returns the time in milliseconds, but on this Linux box I\'m working on, it rounds it to the nearest 1000 so the precision is only to the \"second\" level and not to the milliseconds level. I found a solution with Qt using the QTime class, instantiating an object and calling start() on it then calling elapsed() to get the number of milliseconds elapsed. I got kind of lucky because I\'m working with Qt to begin with, but I\'d like a solution that doesn\'t rely on third