Ok, DEBUG build tests (release build runtimes)
.NET 2.0:
results:
Reading 10000 rows into a datatable took 00:00:01.0316394
Reading 10000 rows into a datatable took 00:00:01.0003776
Reading 10000 rows into a datatable took 00:00:01.0316394
Reading 10000 rows into a datatable took 00:00:01.0003776
Reading 10000 rows into a datatable took 00:00:01.0160085
Reading 10000 rows into a datatable took 00:00:01.0003776
Reading 10000 entities into an entity collection took 00:00:01.7662917
Reading 10000 entities into an entity collection took 00:00:01.2192102
Reading 10000 entities into an entity collection took 00:00:01.1410557
Reading 10000 entities into an entity collection took 00:00:01.0785321
Reading 10000 entities into an entity collection took 00:00:01.1097939
Reading 10000 entities into a collection of custom classes took 00:00:01.6725063
Reading 10000 entities into a collection of custom classes took 00:00:01.4693046
Reading 10000 entities into a collection of custom classes took 00:00:01.4380428
Reading 10000 entities into a collection of custom classes took 00:00:01.4224119
Reading 10000 entities into a collection of custom classes took 00:00:01.4067810
Code:
class Program
{
private const int Amount = 10000;
static void Main( string[] args )
{
DataTableBencher dtBencher = new DataTableBencher();
dtBencher.Bench( Program.Amount ); // dummy, to get sqlserver fired up.
int runs = 5;
for(int i = 0; i < runs; i++)
{
dtBencher = new DataTableBencher();
dtBencher.Bench(Program.Amount);
}
for( int i = 0; i < runs; i++ )
{
AdapterBencher aBencher = new AdapterBencher();
aBencher.Bench( Program.Amount );
}
for( int i = 0; i < runs; i++ )
{
AdapterProjectorBencher apBencher = new AdapterProjectorBencher();
apBencher.Bench( Program.Amount );
}
Console.WriteLine( "Press enter to exit" );
Console.ReadLine();
}
}
public class DataTableBencher
{
public void Bench(int amount)
{
DataTable toFill = new DataTable();
SqlConnection con = new SqlConnection("data source=nerd;initial catalog=BenchmarkData;integrated security=SSPI;persist security info=False;packet size=4096");
SqlCommand cmd = new SqlCommand( string.Format( "SELECT TOP {0} * FROM RandomData", amount ), con );
SqlDataAdapter adapter = new SqlDataAdapter( cmd );
DateTime start = DateTime.Now;
adapter.Fill( toFill );
DateTime end = DateTime.Now;
Console.WriteLine("Reading {0} rows into a datatable took {1}", toFill.Rows.Count, (end-start));
}
}
public class AdapterBencher
{
public void Bench(int amount)
{
EntityCollection<RandomDataEntity> randomData = new EntityCollection<RandomDataEntity>( new RandomDataEntityFactory() );
randomData.Capacity = amount;
DateTime start = DateTime.Now;
using( DataAccessAdapter adapter = new DataAccessAdapter( ) )
{
adapter.FetchEntityCollection( randomData, null, amount );
}
DateTime end = DateTime.Now;
Console.WriteLine( "Reading {0} entities into an entity collection took {1}", randomData.Count, (end - start) );
//Console.WriteLine( "Press enter to exit routine." );
//Console.ReadLine();
}
}
public class AdapterProjectorBencher
{
public void Bench( int amount )
{
List<RandomDataClass> randomData = new List<RandomDataClass>(amount);
List<IDataValueProjector> valueProjectors = new List<IDataValueProjector>();
valueProjectors.Add( new DataValueProjector( "Id", 0, typeof( long ) ) );
valueProjectors.Add( new DataValueProjector( "GuidVal", 1, typeof( Guid ) ) );
valueProjectors.Add( new DataValueProjector( "NullVal", 2, typeof( string) ) );
valueProjectors.Add( new DataValueProjector( "IntVal", 3, typeof( int ) ) );
valueProjectors.Add( new DataValueProjector( "Varchar1Val", 4, typeof( string ) ) );
valueProjectors.Add( new DataValueProjector( "Varchar2Val",5, typeof( string ) ) );
valueProjectors.Add( new DataValueProjector( "ShortVal", 6, typeof( short ) ) );
valueProjectors.Add( new DataValueProjector( "DateVal", 7, typeof( DateTime ) ) );
valueProjectors.Add( new DataValueProjector( "Dummy1", 8, typeof( int ) ) );
valueProjectors.Add( new DataValueProjector( "Dummy2", 9, typeof( int) ) );
valueProjectors.Add( new DataValueProjector( "Dummy3", 10, typeof( int ) ) );
valueProjectors.Add( new DataValueProjector( "Dummy4", 11, typeof( string ) ) );
DataProjectorToCustomClass<RandomDataClass> projector = new DataProjectorToCustomClass<RandomDataClass>( randomData );
IEntityFields2 fields = new RandomDataEntityFactory().CreateFields();
DateTime start = DateTime.Now;
using( DataAccessAdapter adapter = new DataAccessAdapter( ) )
{
adapter.FetchProjection(valueProjectors, projector, fields, null, amount, true);
}
DateTime end = DateTime.Now;
Console.WriteLine( "Reading {0} entities into a collection of custom classes took {1}", randomData.Count, (end - start) );
//Console.WriteLine( "Press enter to exit routine." );
//Console.ReadLine();
}
}
/// <summary>
/// Summary description for RandomDataClass.
/// </summary>
public class RandomDataClass
{
#region Class Member Declarations
private string _nullVal, _varchar1Val, _varchar2Val, _dummy4;
private int _intVal, _dummy1, _dummy2, _dummy3;
private long _id;
private short _shortVal;
private DateTime _dateVal;
private Guid _guidVal;
#endregion
public RandomDataClass()
{
}
/// ... properties declarations, snipped.
}
RELEASE BUILD results:
Reading 10000 rows into a datatable took 00:00:01.0155795
Reading 10000 rows into a datatable took 00:00:00.9999552
Reading 10000 rows into a datatable took 00:00:01.0155795
Reading 10000 rows into a datatable took 00:00:01.0155795
Reading 10000 rows into a datatable took 00:00:00.9999552
Reading 10000 rows into a datatable took 00:00:00.9999552
Reading 10000 entities into an entity collection took 00:00:01.3124412
Reading 10000 entities into an entity collection took 00:00:01.2030711
Reading 10000 entities into an entity collection took 00:00:01.1405739
Reading 10000 entities into an entity collection took 00:00:01.0780767
Reading 10000 entities into an entity collection took 00:00:01.0937010
Reading 10000 entities into a collection of custom classes took 00:00:01.4530599
Reading 10000 entities into a collection of custom classes took 00:00:01.4374356
Reading 10000 entities into a collection of custom classes took 00:00:01.4374356
Reading 10000 entities into a collection of custom classes took 00:00:01.4061870
Reading 10000 entities into a collection of custom classes took 00:00:01.4374356