Consider this benchmark: it has two versions of code that do slightly different things. But each version increases the size of the List by 100000 elements.
using System;
using System.Collections.Generic;
using System.Diagnostics;
const int _max = 10;
var s1 = Stopwatch.StartNew();
// Version 1: insert at index 0.
for (int i = 0; i < _max; i++)
{
List<long> list = new List<long>();
for (long z = 0; z < 100000; z++)
{
list.Insert(0, i);
}
}
s1.Stop();
var s2 = Stopwatch.StartNew();
// Version 2: use Add() method.
for (int i = 0; i < _max; i++)
{
List<long> list = new List<long>();
for (long z = 0; z < 100000; z++)
{
list.Add(i);
}
}
s2.Stop();
Console.WriteLine(((double)(s1.Elapsed.TotalMilliseconds * 1000000) / _max).ToString(
"0.00 ns"));
Console.WriteLine(((double)(s2.Elapsed.TotalMilliseconds * 1000000) / _max).ToString(
"0.00 ns"));
1181336470.00 ns Insert
1002800.00 ns Add