I’ve just updated my prior article on virtual function overhead with corrected timing numbers — I hadn’t noticed that my CPU cycle counts were only 32 bits wide so timings of more than 2secs would wrap back around to zero. If you want to run this test on your own hardware, I’ve put my code […]
Archive for January 2009
Whenever I work with virtual functions I find myself wondering: how much is it costing me to perform all these vtable lookups and indirect calls? The usual truism is that computers are so fast now that it doesn’t matter and that the idea of virtuals being a problem is just another myth. Our beloved Xenon […]
For best float-to-int conversion speed, specify the compiler flag /arch:SSE2 to assume the availability of SSE2 opcodes.
The seemingly simple act of assigning an int to a float variable, or vice versa, can be astonishingly expensive. In some architectures it may cost 40 cycles or even more! The reasons for this have to do with rounding and the load-hit-store issue, but the outcome is simple: never cast a float to an int […]
Branching on floating-point values can be a significant performance penalty. In some cases, using the ternary operator ?: or substituting a conditional-move operator like fsel allows you to make your function branchless and run much faster.