Timing in JS – multiple setIntervals running at once and starting at the same time?

Good question, but in JS you can’t. To have multiple functions in the same program execute at the same time you need multi-threading and some deep timing and thread handling skills. JS is single threaded. setInterval doesn’t acutally run the function after the delay, rather after the delay it adds the function to the event … Read more

Get evaluation timings in GHCi

If you enter :set +s in GHCi, then timing and memory info will be printed after the evaluation of every expression. Example: Prelude> :set +s Prelude> sum [1..2^20] 549756338176 it :: (Num a, Enum a) => a (0.34 secs, 169,197,008 bytes) Note that this will be the timing of the expression as evaluated in the … Read more

Writing a java annotation for timing method call

AFAIK, Tomasz is right in saying that this can’t be done using annotations. I think the confusion stems from the fact that Python decorators and Java annotations share the same syntax but are completely different in terms of the behavior they offer! Annotations are metadata attached to your class/methods/fields. This blog post addresses the point … Read more

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

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

What is the difference between CLOCK_MONOTONIC & CLOCK_MONOTONIC_RAW?

CLOCK_MONOTONIC never experiences discontinuities due to NTP time adjustments, but it does change in frequency as NTP learns what error exists between the local oscillator and the upstream servers. CLOCK_MONOTONIC_RAW is simply the local oscillator, not disciplined by NTP. This could be very useful if you want to implement some other time synchronization algorithm against … Read more

Getting an accurate execution time in C++ (micro seconds)

If you are using c++11 or later you could use std::chrono::high_resolution_clock. A simple use case : auto start = std::chrono::high_resolution_clock::now(); … auto elapsed = std::chrono::high_resolution_clock::now() – start; long long microseconds = std::chrono::duration_cast<std::chrono::microseconds>( elapsed).count(); This solution has the advantage of being portable. Beware that micro-benchmarking is hard. It’s very easy to measure the wrong thing (like … Read more

Why is Collections.sort() much slower than Arrays.sort()?

So, there are two different methods with totally different algorithms here: Arrays.sort(int[]) uses a dual-pivot quicksort algorithm. Collections.sort(List<T>) calls list.sort(null) which in turn calls Arrays.sort(T[]). This uses a Timsort algorithm. So, let’s compare Arrays.sort(int[]) and Arrays.sort(T[]). T[] is a boxed array so there is one extra level of indirection: for each call, you have to … Read more

Is setTimeout with no delay the same as executing the function instantly?

It won’t necessarily run right away, neither will explicitly setting the delay to 0. The reason is that setTimeout removes the function from the execution queue and it will only be invoked after JavaScript has finished with the current execution queue. console.log(1); setTimeout(function() {console.log(2)}); console.log(3); console.log(4); console.log(5); //console logs 1,3,4,5,2 for more details see http://javascriptweblog.wordpress.com/2010/06/28/understanding-javascript-timers/

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