Library tutorials & articles
Iteration Methods
- Introduction
- More Methods
- Conclusions
Introduction
Introduction
I’ve been implementing numerical libraries in .NET and have come to some conclusions about iteration performance. My classes have to hold a large amount of data and be able to iterate through that data as quickly as possible. In order to compare various methods, I created a simple class called Data that encapsulates an array of doubles.
Method #1: Enumeration
Data implements IEnumerable. It contains GetEnumerator which returns its own DataEnumerator, an inner class.
…
public IEnumerator GetEnumerator()
{
return new DataEnumerator( this );
}
internal class DataEnumerator : IEnumerator
{
private Data internal_ = null;
private int index = -1;
public DataEnumerator( Data data )
{
internal_ = data;
}
public object Current
{
get
{
return internal_.Array[index];
}
}
public bool MoveNext()
{
index++;
if ( index >= internal_.Array.Length )
{
return false;
}
return true;
}
public void Reset()
{
index = -1;
}
}
…
Related articles
Related discussion
-
C# video Editing/rendering
by pkuchaliya (0 replies)
-
How to Fill DataSet with more records (around 1 lakh) in a faster way
by Jayaram P (0 replies)
-
Can't print on the network with MSADESS ??
by anatha1 (2 replies)
-
Very Urgent regarding deleting the images from a folder
by Nanosteps (6 replies)
-
DataGridViewComboBoxColumn not showing values
by sachinkalse (0 replies)
Related podcasts
-
Object-Oriented Programming in Ruby
In this episode, I talk with Scott Bellware about object-oriented programming in Ruby, and Ruby's object model. This is taken from a private conversation, and the audio quality suffers at times. Much thanks to Scott for allowing this to be released.This episode of the Alt.NET Podcast is bro...
Thanks for the feedback! I tried putting in the extra step. The results are virtually unchanged from previous changes. Please try it out yourself.
Cheers,
Trevor
Trevor Misfeldt
CEO, CenterSpace Software
You are merely accessing the reference to where the data is kept for the array, but are never actually accessing the data, which you do elsewhere (for example Method #2). If you were to actually access the data, then I think your method would perform similar to Method #2. I don't think that the actual data is read until you access the variable. So perhaps to complete the test, I would perform a d += 1 in each loop to make sure that the data is accessed by each method your base class in which the object exists.
This thread is for discussions of Iteration Methods.