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

<chrono> would be a better library if you’re using C++11. #include <iostream> #include <chrono> #include <thread> void f() { std::this_thread::sleep_for(std::chrono::seconds(1)); } int main() { auto t1 = std::chrono::high_resolution_clock::now(); f(); auto t2 = std::chrono::high_resolution_clock::now(); std::cout << “f() took ” << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count() << ” milliseconds\n”; } Example taken from here.

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

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 … Read more

Is it possible to get a history of queries made in postgres

There’s no history in the database itself, if you’re using psql you can use “\s” to see your command history there. You can get future queries or other types of operations into the log files by setting log_statement in the postgresql.conf file. What you probably want instead is log_min_duration_statement, which if you set it to … Read more

Best timing method in C?

I think this should work: #include <time.h> clock_t start = clock(), diff; ProcessIntenseFunction(); diff = clock() – start; int msec = diff * 1000 / CLOCKS_PER_SEC; printf(“Time taken %d seconds %d milliseconds”, msec/1000, msec%1000);

How to make `setInterval` behave more in sync, or how to use `setTimeout` instead?

You can create a setTimeout loop using recursion: function timeout() { setTimeout(function () { // Do Something Here // Then recall the parent function to // create a recursive loop. timeout(); }, 1000); } The problem with setInterval() and setTimeout() is that there is no guarantee your code will run in the specified time. By … Read more

timeit versus timing decorator

Use wrapping from functools to improve Matt Alcock’s answer. from functools import wraps from time import time def timing(f): @wraps(f) def wrap(*args, **kw): ts = time() result = f(*args, **kw) te = time() print ‘func:%r args:[%r, %r] took: %2.4f sec’ % \ (f.__name__, args, kw, te-ts) return result return wrap In an example: @timing def … Read more

Stopwatch vs. using System.DateTime.Now for timing events [duplicate]

As per MSDN: The Stopwatch measures elapsed time by counting timer ticks in the underlying timer mechanism. If the installed hardware and operating system support a high-resolution performance counter, then the Stopwatch class uses that counter to measure elapsed time. Otherwise, the Stopwatch class uses the system timer to measure elapsed time. Use the Frequency … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)