clock

C++ calculating time intervals

删除回忆录丶 提交于 2019-12-02 02:03:53
I want to calculate time intervals (in 1/10th of 1 second) between some events happening in my program. Thus I use clock function for these needs like follows: clock_t begin; clock_t now; clock_t diff; begin = clock(); while ( 1 ) { now = clock(); diff = now - begin; cout << diff / CLOCKS_PER_SEC << "\n"; //usleep ( 1000000 ); }; I expect the program to print 0 for 1 second, then 1 for 1 sec., then 2 for 1 sec. and so on... In fact it prints 0 for about 8 seconds, then 1 for about 8 seconds and so on... By the way, if I add usleep in order program prints only 1 time per second, it prints only

clock() function always returning 0 [duplicate]

不问归期 提交于 2019-12-02 01:49:01
Possible Duplicate: The C clock() function just returns a zero I ran the following code to test the working of clock() function. I work on ubuntu 12.04. #include <stdio.h> #include <time.h> #include <iostream> using namespace std; double diffclock(clock_t clock1,clock_t clock2) { double diffticks=clock1-clock2; double diffms=(diffticks*10)/CLOCKS_PER_SEC; return diffms; } int main() { string name; int i; clock_t begin=clock(); cout << "Hi what is your name? "; getline(cin, name); clock_t end=clock(); cout << "Time elapsed: " << double(diffclock(end,begin)) << " ms"<< endl; return 0; } But no

extern auto variable has no initializer

折月煮酒 提交于 2019-12-02 00:56:16
I need to use a global timestamp (std::chrono::high_resolution_clock::now()) in my c++ program. I declared it in the header file Header.h: #include<chrono> using namespace std; extern auto start; I want to initialize a value in main, so in main.cpp, I did: #include"Header.h" #include<chrono> using namespace std; auto start; int main(){ start = std::chrono::high_resolution_clock::now(); } However, when compiling it, I got: error: declaration of ‘auto start’ has no initializer Can anybody tell me what I did wrong? Thanks! How is auto supposed to deduce the type of start ? You need to declare the

boost::deadline_timer can fail when system clock is modified

人盡茶涼 提交于 2019-12-01 15:54:35
As could be read at: https://svn.boost.org/trac/boost/ticket/3504 a deadline_timer that timeouts periodically and which is implemented using deadline_timer::expires_at() (like the example in Boost Timer Tutorial, 3th example ) will probably fail if the system time is modified (for example, using the date command, if your operating system is Linux). Is there a simple and appropiate way of performing this operation now, using Boost? I do not want to use deadline_timer::expires_from_now() because I could verify that it is less accurate than "manually" updating the expiry time. As a temporal

boost::deadline_timer can fail when system clock is modified

给你一囗甜甜゛ 提交于 2019-12-01 14:48:06
问题 As could be read at: https://svn.boost.org/trac/boost/ticket/3504 a deadline_timer that timeouts periodically and which is implemented using deadline_timer::expires_at() (like the example in Boost Timer Tutorial, 3th example) will probably fail if the system time is modified (for example, using the date command, if your operating system is Linux). Is there a simple and appropiate way of performing this operation now, using Boost? I do not want to use deadline_timer::expires_from_now() because

JSON time service “json-time.appspot.com” is broken. Anyone have a replacement?

筅森魡賤 提交于 2019-12-01 08:08:36
http://json-time.appspot.com/time.json?tz=GMT has been broken for a while now... at least a month. This service returns the current time in jsonp, and I have a jquery plugin that uses it to determine the correct time. I'm under the assumption that this service is permanently down since it's been down for a long time and I can't find any posts by the author as to it's status. Does anyone know of a service that I can use that returns the correct time in JSON or XML? Thanks! Looks like you can set up your own: https://github.com/simonw/json-time 来源: https://stackoverflow.com/questions/7520793

JSON time service “json-time.appspot.com” is broken. Anyone have a replacement?

£可爱£侵袭症+ 提交于 2019-12-01 06:51:52
问题 http://json-time.appspot.com/time.json?tz=GMT has been broken for a while now... at least a month. This service returns the current time in jsonp, and I have a jquery plugin that uses it to determine the correct time. I'm under the assumption that this service is permanently down since it's been down for a long time and I can't find any posts by the author as to it's status. Does anyone know of a service that I can use that returns the correct time in JSON or XML? Thanks! 回答1: Looks like you

Calculating CPU frequency in C with RDTSC always returns 0

a 夏天 提交于 2019-12-01 06:43:41
The following piece of code was given to us from our instructor so we could measure some algorithms performance: #include <stdio.h> #include <unistd.h> static unsigned cyc_hi = 0, cyc_lo = 0; static void access_counter(unsigned *hi, unsigned *lo) { asm("rdtsc; movl %%edx,%0; movl %%eax,%1" : "=r" (*hi), "=r" (*lo) : /* No input */ : "%edx", "%eax"); } void start_counter() { access_counter(&cyc_hi, &cyc_lo); } double get_counter() { unsigned ncyc_hi, ncyc_lo, hi, lo, borrow; double result; access_counter(&ncyc_hi, &ncyc_lo); lo = ncyc_lo - cyc_lo; borrow = lo > ncyc_lo; hi = ncyc_hi - cyc_hi -

Clock in different time zones

*爱你&永不变心* 提交于 2019-12-01 04:47:34
I am trying to create two clocks on a website that says two times on it. One from London and the other from New York. I have been able to create a clock that reads the current time on my computer but i'm not sure how to place a time zone into this. The code I have so far is: <script type="text/javascript" language="javascript"> function renderTime() { var currentTime = new Date(); var diem = "AM"; var h = currentTime.getHours(); var m = currentTime.getMinutes(); var s = currentTime.getSeconds(); if (h == 0) { h = 12 } else if (h > 12) { h = h - 12; diem = "PM"; } if (h < 10) { h = "0" + h; }

Calculating CPU frequency in C with RDTSC always returns 0

空扰寡人 提交于 2019-12-01 04:45:50
问题 The following piece of code was given to us from our instructor so we could measure some algorithms performance: #include <stdio.h> #include <unistd.h> static unsigned cyc_hi = 0, cyc_lo = 0; static void access_counter(unsigned *hi, unsigned *lo) { asm("rdtsc; movl %%edx,%0; movl %%eax,%1" : "=r" (*hi), "=r" (*lo) : /* No input */ : "%edx", "%eax"); } void start_counter() { access_counter(&cyc_hi, &cyc_lo); } double get_counter() { unsigned ncyc_hi, ncyc_lo, hi, lo, borrow; double result;