Statistical test on C code performance

While curious on how C code are optimized by compiler on mathematical functions, two implementations of the standard normal distribution are compared in terms of performance. The aim is to provide insight on how the generated machine code performs, without having to actually inspecting them. The function is an approximation function coded in standard C. It should be noted that both functions implement the same approximation, but the actual equation is a little bit different in terms of number of multiplication operator. The first implementation is with less multiplication operators:

While the second one is a modified version with more multiplication operators, e.g. expanding k5 to k*k*k*k*k.

A scaffolding test rig is used to loop 10 million times, within it, the approximation function is called from 0 to 1 in steps of 0.1. Visual Studio is used for the code compilation, and 20 samples are collected from each of the two functions. For the analysis, the TI-84 Pocket SE is used to carry out 2-sample T test in the procedure below:


By evaluating the p-value, It looks like the first version of more compact C code performed better and perhaps there is little the compiler can help here.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s