clock

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

落花浮王杯 提交于 2019-11-27 08:39:35
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", ((double) (end - start))); printf("cpu_time_used = %.15f\n", cpu_time_used); printf("CLOCKS_PER_SEC = %i\n\n",

Monotonic clock on OSX

ぃ、小莉子 提交于 2019-11-27 08:03:29
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 just speculation. Does anyone know how mach_absolute_time actually works? I'm actually looking for a

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

人走茶凉 提交于 2019-11-27 07:05:25
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! Just trying to improve Armen's answer. You can use the $interval service to setup a timer. var module = angular.module('myApp', []); module.controller(

pygame.time.set_timer confusion?

空扰寡人 提交于 2019-11-27 06:55:19
问题 So, I have a problem, I don't fully understand the event that is needed to be given to a timer command anyway, it doesn't say anywhere online, to where I searched for hours. So I just used what most people seemed to be using 'USEREVENT + 1'. I'm not sure if it is correct, but my timer is not working. Am I using it correctly? Here is my code: nyansecond=462346 nyanint=0 spin=0 aftin=452345 def nyanmusic(nyansecond,nyanint,spin): if nyanint == 0: nyansound.play() nyanint= 1 elif nyanint == 1:

How do I set the Windows system clock to the correct local time using C#?

我怕爱的太早我们不能终老 提交于 2019-11-27 06:48:47
问题 How do I set the Windows system clock to the correct local time using C#? 回答1: You will need to P/Invoke the SetLocalTime function from the Windows API. Declare it like this in C#: [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] internal static extern bool SetLocalTime(ref SYSTEMTIME lpSystemTime); [StructLayout(LayoutKind.Sequential)] internal struct SYSTEMTIME { public ushort wYear; public ushort wMonth; public ushort wDayOfWeek; // ignored for the SetLocalTime

Update TextView Every Second

怎甘沉沦 提交于 2019-11-27 06:33:39
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 yyyy"; // 01 January 2013 tvDate.setText(DateFormat.format(date, noteTS)); I basically want the setText

why C clock() returns 0

孤街浪徒 提交于 2019-11-27 05:27:59
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 Linux. The result of uname -a is: Linux snowy.*****.ac.uk 2.6.32-71.el6.x86_64 #1 SMP Fri May 20 03:51:51 BST 2011

How precise is the internal clock of a modern PC?

别等时光非礼了梦想. 提交于 2019-11-27 04:33:23
问题 I know that 10 years ago, typical clock precision equaled a system-tick, which was in the range of 10-30ms. Over the past years, precision was increased in multiple steps. Nowadays, there are ways to measure time intervals in actual nanoseconds. However, usual frameworks still return time with a precision of only around 15ms. My question is, which steps did increase the precision, how is it possible to measure in nanoseconds, and why are we still often getting less-than-microsecond precision

Why is CLOCKS_PER_SEC not the actual number of clocks per second?

允我心安 提交于 2019-11-27 04:04:24
I have just written this short C++ program to approximate the actual number of clock ticks per second. #include <iostream> #include <time.h> using namespace std; int main () { for(int i = 0; i < 10 ; i++) { int first_clock = clock(); int first_time = time(NULL); while(time(NULL) <= first_time) {} int second_time = time(NULL); int second_clock = clock(); cout << "Actual clocks per second = " << (second_clock - first_clock)/(second_time - first_time) << "\n"; cout << "CLOCKS_PER_SEC = " << CLOCKS_PER_SEC << "\n"; } return 0; } When I run the program, I get output that looks like this. Actual

How can I locally detect iPhone clock advancement by a user between app runs?

牧云@^-^@ 提交于 2019-11-27 01:46:32
A common exploit in casual games is to artificially advance the system clock to jump ahead in gameplay. How can such user clock advancement be detected by an app on an iOS device? Must not involve network communication Must not assume app is open (running or suspended) while clock is advanced Must detect clock advancement, detecting clock rollback is not sufficient Ideally, the solution would be robust against reboots, but that is not a requirement. Lio CACurrentMediaTime & mach_absolute_time Take a look at this questions: iOS: How to measure passed time, independent of clock and time zone