collection class performance seems SLOOOWWWWWW

Tech-Archive recommends: Fix windows errors by optimizing your registry



I have a small sellection of code here. When the "button1_Click" is
called the performance is quite poor (~ 0.5 sec). Only thing is I am
not really doing anything!! In C++ the same thing takes ~ 0 seconds to
execute!!. The List<Pumpicle> is faster than ArrayList and I convert
the List to an array before access. It just seems to be something like
unboxing the doubles out of the Pumpicle class. Any ideas??

PumpicleContainer pc = null;

private void Form1_Load(object sender, EventArgs e)
{
pc = new PumpicleContainer();

for (int i = 0; i < 10000; i++)
{
pc.Add(new Pumpicle());
}

pc.ToArray();
}

public class DaublePoint
{
public double m_x;
public double m_y;
public double m_z;
};

public class Pumpicle
{
public DaublePoint m_pos;
public double m_mass;

public Pumpicle()
{
m_pos = new DaublePoint();
}
};

class PumpicleContainer
{
public List<Pumpicle> m_pList = new List<Pumpicle>();

Pumpicle[] m_arr = null;

public void Add(Pumpicle p)
{
m_pList.Add(p);
}

public void ToArray()
{
m_arr = m_pList.ToArray();
}

public Pumpicle GetParticle(int i)
{
return m_arr[i];
}
}

private void button1_Click(object sender, EventArgs e)
{
pc.ToArray();

long start = System.DateTime.Now.Ticks;

int np = 0;
for (int idx = 0; idx < 20; idx++)
{
np += 22;
for (int i = -33; i <= 33; i++)
{
for (int j = -33; j <= 33; j++)
{
for (int l = 0; l < 5; l++)
{
for (int ps = 0; ps < np; ps++)
{
Pumpicle p = pc.GetParticle(ps);

DaublePoint pt = p.m_pos;
double x = pt.m_x;
double y = pt.m_y;
double z = pt.m_z;
}
}
}
}
}

long end = System.DateTime.Now.Ticks;

MessageBox.Show("Finished = " + ((end - start) / 1e7));
}

.


Quantcast