timing

c++ Implementing Timed Callback function

喜欢而已 提交于 2019-11-28 18:25:08
I want to implement some system in c++ so that I can call a function and ask for another function to be called in X milliseconds. Something like this: callfunctiontimed(25, funcName); 25 being the amount of milliseconds before the function should be called. I would like to know if multithreading is required for this and then use some delay function? Other than using function pointer how would a feature like this work? For a portable solution, you can use boost::asio. Below is a demo I wrote a while ago. You can change t.expires_from_now(boost::posix_time::seconds(1)); to suit you need say make

What is the difference between CLOCK_MONOTONIC & CLOCK_MONOTONIC_RAW?

时光总嘲笑我的痴心妄想 提交于 2019-11-28 17:50:05
According to the Linux man page under Ubuntu CLOCK_MONOTONIC Clock that cannot be set and represents monotonic time since some unspecified starting point. CLOCK_MONOTONIC_RAW (since Linux 2.6.28; Linux-specific) Similar to CLOCK_MONOTONIC, but provides access to a raw hard‐ ware-based time that is not subject to NTP adjustments. According to the webster online dictionary Monotonic means: 2: having the property either of never increasing or of never decreasing as the values of the independent variable or the subscripts of the terms increase. In other words, it won't jump backwards. I can see

Timing algorithm: clock() vs time() in C++

女生的网名这么多〃 提交于 2019-11-28 15:43:53
问题 For timing an algorithm (approximately in ms), which of these two approaches is better: clock_t start = clock(); algorithm(); clock_t end = clock(); double time = (double) (end-start) / CLOCKS_PER_SEC * 1000.0; Or, time_t start = time(0); algorithm(); time_t end = time(0); double time = difftime(end, start) * 1000.0; Also, from some discussion in the C++ channel at Freenode, I know clock has a very bad resolution, so the timing will be zero for a (relatively) fast algorithm. But, which has

How to enable build timing in Xcode?

こ雲淡風輕ζ 提交于 2019-11-28 14:25:04
问题 I'd like to know how long my project's builds take, for example by displaying it in the build pane. Is this option available somewhere in Xcode? Thanks. 回答1: Type this in the terminal: defaults write com.apple.dt.Xcode ShowBuildOperationDuration YES Duration appears in the activity viewer after a build, alongside the "Succeeded" message. If you are running the app, the status will be replaced by the running status before you can see the duration. This replaces the entry that was used in older

Get mobile cell tower timing advance on Android 2.3

徘徊边缘 提交于 2019-11-28 09:22:03
问题 I need to get the mobile cell tower timing advance. Is it possible on Android 2.3+ ? [edit] It seems that it's not possible to retreive the timing advance... Is it possible to know the distance between the mobile and the cell and the bearing otherwise ? I suppose I can't use the Google hidden geolocation api in commercial application ;-) [/edit] Thanks 回答1: This is currently not implemented, and it will be a hard task because it is device-dependent. The actual timing advance is only known by

Java performance timing library

╄→尐↘猪︶ㄣ 提交于 2019-11-28 05:25:29
I frequent wrap code in a System.nanoTime() pair in order to timing it. Something like: long start = System.nanoTime(); methodToBeTimed(); long elapsedTime = System.nanoTime() - start; There is any good timing library that helps with this problem? Also homegrown code will be accepted. NB A profiler is not a solution here, since I want to enforce some time constraints in my unit tests, so I want to timing methods programmatically . I haven't used it but I came across perf4j recently. Not a direct answer to your question, but I am also often using this tip to time my code and just wrote the

How do I measure duration in seconds in a shell script?

非 Y 不嫁゛ 提交于 2019-11-28 04:16:20
I wish to find out how long an operation takes in a Linux shell script. How can I do this? Using the time command, as others have suggested, is a good idea. Another option is to use the magic built-in variable $SECONDS, which contains the number of seconds since the script started executing. You can say: START_TIME=$SECONDS dosomething ELAPSED_TIME=$(($SECONDS - $START_TIME)) I think this is bash-specific, but since you're on Linux, I assume you're using bash. Use the time command. time ls /bin . Try following example: START_TIME=$SECONDS # do something sleep 65 ELAPSED_TIME=$(($SECONDS -

differences between “d = dict()” and “d = {}”

萝らか妹 提交于 2019-11-28 04:07:45
$ python2.7 -m timeit 'd={}' 10000000 loops, best of 3: 0.0331 usec per loop $ python2.7 -m timeit 'd=dict()' 1000000 loops, best of 3: 0.19 usec per loop Why use one over the other? I'm one of those who prefers words to punctuation -- it's one of the reasons I've picked Python over Perl, for example. "Life is better without braces" (an old Python motto which went on a T-shirt with a cartoon of a smiling teenager;-), after all (originally intended to refer to braces vs indentation for grouping, of course, but, hey, braces are braces!-). "Paying" some nanoseconds (for the purpose of using a

Python class @property: use setter but evade getter?

半腔热情 提交于 2019-11-28 03:54:41
In python classes, the @property is a nice decorator that avoids using explicit setter and getter functions. However, it comes at a cost of an overhead 2-5 times that of a "classical" class function. In my case, this is quite OK in the case of setting a property, where the overhead is insignificant compared to the processing that needs to be done when setting. However, I need no processing when getting the property. It is always just "return self.property". Is there an elegant way to use the setter but not using the getter, without needing to use a different internal variable? Just to

What happens when QueryPerformanceCounter is called?

白昼怎懂夜的黑 提交于 2019-11-27 20:09:01
I'm looking into the exact implications of using QueryPerformanceCounter in our system and am trying to understand it's impact on the application. I can see from running it on my 4-core single cpu machine that it takes around 230ns to run. When I run it on a 24-core 4 cpu xeon it takes around 1.4ms to run. More interestingly on my machine when running it in multiple threads they don't impact each other. But on the multi-cpu machine the threads cause some sort of interaction that causes them to block each other. I'm wondering if there is some shared resource on the bus that they all query? What