Why is dynamic array "constructor" much slower than SetLength and elements initialization? : <p>I was comparing performances between these two ways of initializing a dynamic array:</p>

<pre><code>Arr := TArray&lt;integer&gt;.Create(1, 2, 3, 4, 5);
</code></pre>

<p>and</p>

<pre><code>SetLength(Arr, 5);
Arr[0] := 1;
Arr[1] := 2;
Arr[2] := 3;
Arr[3] := 4;
Arr[4] := 5;
</code></pre>

<p>I've prepared a test and I've noticed that using the array "constructor" takes twice the time required by the other method.</p>

<p><strong>Test:</strong></p>

<pre><code>uses
  DateUtils;

function CreateUsingSetLength() : TArray&lt;integer&gt;;
begin
  SetLength(Result, 5);
  Result[0] := 1;
  Result[1] := 2;
  Result[2] := 3;
  Result[3] := 4;
  Result[4] := 5;
end;
</code></pre>

<p>...</p>

<pre><code>const
  C_COUNT = 10000000;
var
  Start : TDateTime;
  i : integer;
  Arr : TArray&lt;integer&gt;;
  MS1 : integer;
  MS2 : integer;
begin
  Start := Now;
  i := 0;
  while(i &lt; C_COUNT) do
  begin
    Arr := TArray&lt;integer&gt;.Create(1, 2, 3, 4, 5);
    Inc(i);
  end;
  MS1 := MillisecondsBetween(Now, Start);

  Start := Now;
  i := 0;
  while(i &lt; C_COUNT) do
  begin
    Arr := CreateUsingSetLength();
    Inc(i);
  end;
  MS2 := MillisecondsBetween(Now, Start);

  ShowMessage('Constructor = ' + IntToStr(MS1) + sLineBreak + 'Other method = ' + IntToStr(MS2));
</code></pre>

<p>Testing on my machine, the resulting values are always near the following:</p>

<blockquote>
  <p>Constructor = 622 </p>
  
  <p>Other method = 288</p>
</blockquote>

<p>Why is the array "constructor" so slow?</p>
