clock

How do I calculate the elapsed time of an event in java? [duplicate]

大兔子大兔子 提交于 2019-11-26 18:41:32
This question already has an answer here: How do I time a method's execution in Java? 37 answers What's a simple/easy way to access the system clock using Java, so that I can calculate the elapsed time of an event? Leigh I would avoid using System.currentTimeMillis() for measuring elapsed time. currentTimeMillis() returns the 'wall-clock' time, which may change (eg: daylight savings, admin user changing the clock) and skew your interval measurements. System.nanoTime() , on the other hand, returns the number of nanoseconds since 'some reference point' (eg, JVM start up), and would therefore not

How do I get monotonic time durations in python?

匆匆过客 提交于 2019-11-26 18:41:29
I want to log how long something takes in real walltime. Currently I'm doing this: startTime = time.time() someSQLOrSomething() print "That took %.3f seconds" % (time.time() - startTime) But that will fail (produce incorrect results) if the time is adjusted while the SQL query (or whatever it is) is running. I don't want to just benchmark it. I want to log it in a live application in order to see trends on a live system. I want something like clock_gettime(CLOCK_MONOTONIC,...), but in Python. And preferably without having to write a C module that calls clock_gettime(). Armin Ronacher That

How to use clock() in C++

自作多情 提交于 2019-11-26 18:10:29
How do I call clock() in C++ ? For example, I want to test how much time a linear search takes to find a given element in an array. #include <iostream> #include <cstdio> #include <ctime> int main() { std::clock_t start; double duration; start = std::clock(); /* Your algorithm here */ duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC; std::cout<<"printf: "<< duration <<'\n'; } An alternative solution, which is portable and with higher precision, available since C++11, is to use std::chrono . Here is an example: #include <iostream> #include <chrono> typedef std::chrono::high

Linux clock_gettime(CLOCK_MONOTONIC) strange non-monotonic behavior

一个人想着一个人 提交于 2019-11-26 17:38:13
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 implementation of clock_gettime ? I'm using Ubuntu Server Edition 10.04 (kernel 2.6.32-24, x86_64), gcc

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

二次信任 提交于 2019-11-26 17:32:02
问题 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 = " <<

Intent to launch the clock application on android

我与影子孤独终老i 提交于 2019-11-26 17:30:31
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 pendingIntent = PendingIntent.getActivity(context, 0, AlarmClockIntent, 0); views.setOnClickPendingIntent(R.id.Widget

How do I generate an alert at a specific time in C#?

自古美人都是妖i 提交于 2019-11-26 16:13:33
问题 How can i generate an event at a specific time? For example, say I want to generate an alert at 8:00 AM that informs me its 8:00 AM (or an event that informs me of the current time at any given time). 回答1: Use the System.Threading.Timer class: var dt = ... // next 8:00 AM from now var timer = new Timer(callback, null, dt - DateTime.Now, TimeSpan.FromHours(24)); The callback delegate will be called the next time it's 8:00 AM and every 24 hours thereafter. See this SO question how to calculate

Understanding the different clocks of clock_gettime()

断了今生、忘了曾经 提交于 2019-11-26 15:55:53
问题 Hi I wanted to use the clock_gettime() function for measuring the performance of my code. I am unable to understand the difference between the different kinds of clocks used in the function from the man page descriptions. esp CLOCK_REALTIME, CLOCK_PROCESS_CPUTIME_ID CLOCK_THREAD_CPUTIME_ID Can someone explaing what each of these clocks do? 回答1: CLOCK_REALTIME reports the actual wall clock time. CLOCK_MONOTONIC is for measuring relative real time. It advances at the same rate as the actual

Listing of manufacturer&#39;s clock / alarm package and class name, Please add

耗尽温柔 提交于 2019-11-26 15:41:36
问题 THis is not really a question, Sorry. I just wanted help on getting the package and class names of alarm and clocks of different android makers' clock and alarm. I have a listing here of HTC, Samsung, and stock android class names. But you can guess the package names. // HTC "com.htc.android.worldclock.TimerAlert",// "com.htc.android.worldclock.AlarmAlert",// // Samsung "com.sec.android.app.clockpackage.ClockPackage",// "com.sec.android.app.clockpackage.alarm.AlarmAlert",// // Motorola "com

How to create a JQuery Clock / Timer

僤鯓⒐⒋嵵緔 提交于 2019-11-26 14:17:31
I have a simple quiz application and I want display a nice timer / clock at the top of the page which shows the user how long they've been going for. (If I could somehow show them a timer for Total Quiz Time and also a second one for This Question Time that would be even cooler but I should be able to figure out how to do myself that once I've got one timer working. My question is: What's a nice, easy way to show a simple timer / clock using JQuery? (straight JS is also ok) I know how to check time, but how do I get incrementing seconds? My own searches keep leading me to JQuery plugins (I