Wednesday, August 27, 2008

pre-increment or post-increment?

Which is faster? Here it is quick and dirty - post-increment can never be faster than pre-increment, but can sometimes be slower. Why? There's an extra copy happening in the post-increment due to saving the value THEN incrementing. So, what would you prefer? C++ or ++C?

QueryPerformanceFrequency Accuracy

In doing recent high accuracy timings, I've found that the Windows API call, QueryPerformanceFrequency, returns a constant nominal processor frequency. Under ideal conditions, this would be great. Unfortunately, we don't live in an ideal world, let alone ideal conditions, given most circumstances. I guess the clocks that feed the processors are notorious for having skewed frequencies, depending on the heat generated from the varying load on the processor. Due to this, QueryPerformanceFrequency returns a constant locked in frequency that should be the most accurate frequency under nominal conditions, and is the best approximation of the clock frequency over a long duration. When performing any sort of high accuracy timing within short time periods, this can be quite a factor!