15

6

When you pack lists there is an overhead therefore packing a list with, say, 2 elements is likely to cost more than you get back in efficiency. Mathematica has default list lengths for which functions creating those lists will pack the list (i.e. if the list length is less than the numbers shown below the list will not be packed):

```
SystemOptions["CompileOptions"]
{"CompileOptions" -> {"ApplyCompileLength" -> \[Infinity],
"ArrayCompileLength" -> 250, "AutoCompileAllowCoercion" -> False,
"AutoCompileProtectValues" -> False, "AutomaticCompile" -> False,
"BinaryTensorArithmetic" -> False, "CompileAllowCoercion" -> True,
"CompileConfirmInitializedVariables" -> True,
"CompiledFunctionArgumentCoercionTolerance" -> 2.10721,
"CompiledFunctionMaxFailures" -> 3,
"CompileDynamicScoping" -> False,
"CompileEvaluateConstants" -> True,
"CompileOptimizeRegisters" -> False,
"CompileReportCoercion" -> False, "CompileReportExternal" -> False,
"CompileReportFailure" -> False, "CompileValuesLast" -> True,
"FoldCompileLength" -> 100, "InternalCompileMessages" -> False,
"ListableFunctionCompileLength" -> 250, "MapCompileLength" -> 100,
"NestCompileLength" -> 100, "NumericalAllowExternal" -> False,
"ProductCompileLength" -> 250, "ReuseTensorRegisters" -> True,
"SumCompileLength" -> 250, "SystemCompileOptimizations" -> All,
"TableCompileLength" -> 250}}
```

So, for example, if you make a list using `Table`

```
Developer`PackedArrayQ[Table[i, {i, 1, 249}]]
False
Developer`PackedArrayQ[Table[i, {i, 1, 251}]]
True
```

I am assuming that if you plotted the time to make uncompiled lists using `Table`

, vs making compiled lists, the lines would intersect at ~250, beyond which packed lists become more efficient. Is that a correct interpetation of what the autocompilation length represents?

I would expect that the optimal lengths for compilation (incl. packing) vary on system to system, therefore I want to know the best way to construct a set of tests to test that proposition, and to determine the optimal list length for packing for the functions listed above.

**Edit**

For clarity, as per Albert's comments, there are cases when the evaluations taking place prevent compilation so these discussions are redundant, i.e. compilation is prevented regardless of the default settings. But I am curious about the optimal list lengths in cases where compilation occurs.

BTW maybe someone from Wolfram could comment about why the

`Apply`

compile length is set to infinity. – Mike Honeychurch – 2012-01-19T23:55:28.563Apply replaces the head of an expr. It needs to unpack at some stage. – None – 2012-01-20T07:27:49.170

@ruebenko, of course! thanks :) Having said that, what is the point of having an option for

`Apply`

compile length? – Mike Honeychurch – 2012-01-20T08:38:00.570I never tried this, but I think the computation which in the end computes with what the head is replaced may be expensive, in this case then you might get a benefit from a compiled function; but I think this is rare. – None – 2012-01-20T08:43:36.800