clock

clock_gettime alternative in Mac OS X

谁说胖子不能爱 提交于 2019-11-26 14:06:16
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 . Jens Gustedt In effect, it seems not to be implemented for macOS before Sierra 10.12. You may want to look at

Monotonic clock on OSX

纵然是瞬间 提交于 2019-11-26 13:57:55
问题 CLOCK_MONOTONIC does not seem available, so clock_gettime is out. I've read in some places that mach_absolute_time() might be the right way to go, but after reading that it was a 'cpu dependent value', it instantly made me wonder if it is using rtdsc underneath. Thus, the value could drift over time even if it is monotonic. Also, issues with thread affinity could result in meaningfully different results from calling the function (making it not monotonic across all cores). Of course, that is

How to make a ticking clock (time) in AngularJS and HTML

北战南征 提交于 2019-11-26 13:02:51
问题 I\'m a beginner AngularJS/html user who\'s been trying to find a code snippet to make a clock/time item for a web app. A web search did not provide straight-forward results as easily as I would expect them for something so trivial, so I thought I would post this question to get some answers and also make this easier to find for others. I have posted my solution but want to see if there is anything nicer out there before choosing an answer! 回答1: Just trying to improve Armen's answer. You can

Issue when scheduling tasks using clock() function

风流意气都作罢 提交于 2019-11-26 12:17:39
问题 I would like to schedule tasks at different time intervals: at 0.1 sec, 0.9s .... 2s etc I use the clock() C++ function that returns the number of ticks since the beginning of the simulation and I convert the ticks number to seconds using CLOCKS_PER_SEC but I have noticed that the task isn\'t scheduled when the instant is a float, but when it\'s an integer it does. Here the portion of the code responsible for the scheduling: float goal = (float) clock() / CLOCKS_PER_SEC + 0.4 ; // initially

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

孤街醉人 提交于 2019-11-26 12:07:28
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? I think I worked it out. time() carries on incrementing while the device is asleep, but of course can be manipulated by the operating system or user. However, the Kernel boottime (a

Update TextView Every Second

吃可爱长大的小学妹 提交于 2019-11-26 12:03:43
问题 I\'ve looked around and nothing seems to be working from what I\'ve tried so far... @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.deskclock); TextView tvTime = (TextView) findViewById(R.id.tvTime); TextView tvDate = (TextView) findViewById(R.id.tvDate); java.util.Date noteTS = Calendar.getInstance().getTime(); String time = \"hh:mm\"; // 12:00 tvTime.setText(DateFormat.format(time, noteTS)); String date = \"dd MMMMM

why C clock() returns 0

两盒软妹~` 提交于 2019-11-26 11:35:35
问题 I\'ve got something like this: clock_t start, end; start=clock(); something_else(); end=clock(); printf(\"\\nClock cycles are: %d - %d\\n\",start,end); and I always get as an output \"Clock cycles are: 0 - 0\" Any idea why this happens? (Just to give little detail, the something_else() function performs a left-to-right exponentiation using montgomery representation, moreover I don\'t know for certain that the something_else() function does indeed take some not negligible time.) This is on

The C `clock()` function just returns a zero

只愿长相守 提交于 2019-11-26 11:14:08
问题 The C clock() function just returns me a zero. I tried using different types, with no improvement... Is this a good way to measure time with good precision? #include <time.h> #include <stdio.h> int main() { clock_t start, end; double cpu_time_used; char s[32]; start = clock(); printf(\"\\nSleeping 3 seconds...\\n\\n\"); sleep(3); end = clock(); cpu_time_used = ((double)(end - start)) / ((double)CLOCKS_PER_SEC); printf(\"start = %.20f\\nend = %.20f\\n\", start, end); printf(\"delta = %.20f\\n\

faster equivalent of gettimeofday

半世苍凉 提交于 2019-11-26 09:06:14
问题 In trying to build a very latency sensitive application, that needs to send 100s of messages a seconds, each message having the time field, we wanted to consider optimizing gettimeofday. Out first thought was rdtsc based optimization. Any thoughts ? Any other pointers ? Required accurancy of the time value returned is in milliseconds, but it isn\'t a big deal if the value is occasionally out of sync with the receiver for 1-2 milliseconds. Trying to do better than the 62 nanoseconds

Will docker container auto sync time with the host machine?

无人久伴 提交于 2019-11-26 08:45:15
问题 Giving I already changed the timezone of docker container correctly. Do I need to install a NTP server inside the docker container to periodically sync the time or the container will sync the time from its host machine? 回答1: If you are on OSX running boot2docker, see this issue: https://github.com/boot2docker/boot2docker/issues/290 Time synch becomes an issue because the boot2docker host has its time drift while your OS is asleep. Time synch with your docker container cannot be resolved by