The default setting of
Automatic generates more efficient code by avoiding computing the same result more than once:
When the optimization level is reduced, less efficient code is generated:
This generates C code and links it back in for execution:
This is a larger example that demonstrates the speed advantages of C code generation:
The default operation runs more slowly:
Listable compiled functions can execute in parallel using threads:
This shows the operation running sequentially:
Typically,
$ProcessorCount is used to determine how many threads to be used:
You can combine parallel operations with C code generation to get even faster operation:
This creates a listable compiled function:
It operates on a single input in normal fashion:
When the arguments include a list that does not match the input specification, it threads over that argument:
If there is a branch, listability needs a function to be defined, as shown below using
Function:
A listable compiled function is equivalent but executes faster:
A listable compiled function can run in parallel, giving an acceleration on multicore machines:
Using the listable attribute is typically faster than invoking
CompiledFunction many times:
Using parallelization can give an even greater speedup:
The results are identical:
A detailed plot of the basins of attraction for Newton's method for

:
Typically, integer arithmetic overflow is caught and the computation switches to use bignums:
Turning off overflow checking makes for faster execution, but the result can be incorrect: