I wrote a C # class that populates the "List of Doubling Lists" with some data (no matter what the data is, at the moment it might just be garbage :)) for testing purposes:
Here is the code:
class test { public test() { _myListOfList = new List<List<double>>(1000000); } public void Run() { for (int i = 0; i < _myListOfList.Capacity; i++) { _myListOfList.Add( new List<double>(3) { i, 10*i, 100*i} );
I compared the execution speed of this code with the following: (replacing List of double with Tuple)
class test { public test() { _myListOfTuple = new List<Tuple<double, double, double>>(1000000); } public void Run() { for (int i = 0; i < _myListOfTuple.Capacity; i++) { _myListOfTuple.Add( new Tuple<double, double, double>(i, 10 * i, 100 * i) );
It turns out that using Tuple seems much faster. I ran this piece of code for different sizes of the list (from 200,000 items → 5 million items in the list), and here are the results that I get:

I can not outline the head. Why am I getting such a big difference? Using a tuple that stores an object of the same type (doubles here) does not make much sense. I would prefer to use List / array for this: what am I doing wrong? Is there a way to make case # 1 run faster / faster than case # 2?
Thanks!
source share