What is the effect of ordering if…else if statements by probability?

As a general rule, most if not all Intel CPUs assume forward branches are not taken the first time they see them. See Godbolt’s work. After that, the branch goes into a branch prediction cache, and past behavior is used to inform future branch prediction. So in a tight loop, the effect of misordering is … Read more

Is !important bad for performance?

It shouldn’t have any discernible effects on performance. Seeing Firefox’s CSS parser at /source/layout/style/nsCSSDataBlock.cpp#572 and I think that is the relevant routine, handling overwriting of CSS rules. It just seems to be a simple check for “important”. if (aIsImportant) { if (!HasImportantBit(aPropID)) changed = PR_TRUE; SetImportantBit(aPropID); } else { // … } Also, comments at … Read more

What does gcc’s ffast-math actually do?

-ffast-math does a lot more than just break strict IEEE compliance. First of all, of course, it does break strict IEEE compliance, allowing e.g. the reordering of instructions to something which is mathematically the same (ideally) but not exactly the same in floating point. Second, it disables setting errno after single-instruction math functions, which means … Read more

Unexpected outcome of node.js vs ASP.NET Core performance test

As many others have alluded, the comparison lacks context. At the time of its release, the async approach of node.js was revolutionary. Since then other languages and web frameworks have been adopting the approaches they took mainstream. To understand what the difference meant, you need to simulate a blocking request that represents some IO workload, … Read more

Why is MATLAB so fast in matrix multiplication?

This kind of question is recurring and should be answered more clearly than “MATLAB uses highly optimized libraries” or “MATLAB uses the MKL” for once on Stack Overflow. History: Matrix multiplication (together with Matrix-vector, vector-vector multiplication and many of the matrix decompositions) is (are) the most important problems in linear algebra. Engineers have been solving … Read more