|
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Reflection;
using System.Reflection.Emit;
namespace DynamicMappingSpike
{
public class Program
{
static void Main(string[] args)
{
SqlConnection connection = new SqlConnection("Data Source=localhost; Initial Catalog=SpikeDB;Integrated Security=True");
SqlCommand command = new SqlCommand("Select * From LoadSpike2", connection);
connection.Open();
LoadManually(command);
LoadUsingReflection(command);
LoadUsingDynamicCode(command);
connection.Close();
Console.WriteLine("Done!");
Console.Read();
}
private static void LoadManually(SqlCommand command)
{
DateTime start = DateTime.Now;
Console.WriteLine("Start Manual Load: {0}", start);
using (SqlDataReader reader = command.ExecuteReader())
{
ManualBuilder builder = new ManualBuilder();
while (reader.Read())
{
Person person = builder.Build(reader);
}
}
DateTime stop = DateTime.Now;
Console.WriteLine("Stop Manual Load: {0}", stop);
Console.WriteLine("Elapsed Time: {0}", stop - start);
Console.WriteLine();
}
private static void LoadUsingReflection(SqlCommand command)
{
DateTime start = DateTime.Now;
Console.WriteLine("Start Reflection Load: {0}", start);
using (SqlDataReader reader = command.ExecuteReader())
{
ReflectionBuilder<Person> builder = ReflectionBuilder<Person>.CreateBuilder(reader);
while (reader.Read())
{
Person person = builder.Build(reader);
}
}
DateTime stop = DateTime.Now;
Console.WriteLine("Stop Reflection Load: {0}", stop);
Console.WriteLine("Elapsed Time: {0}", stop - start);
Console.WriteLine();
}
private static void LoadUsingDynamicCode(SqlCommand command)
{
DateTime start = DateTime.Now;
Console.WriteLine("Start Dynamic Load: {0}", start);
using (SqlDataReader reader = command.ExecuteReader())
{
DynamicBuilder<Person> builder = DynamicBuilder<Person>.CreateBuilder(reader);
while (reader.Read())
{
Person person = builder.Build(reader);
}
}
DateTime stop = DateTime.Now;
Console.WriteLine("Stop Dynamic Load: {0}", stop);
Console.WriteLine("Elapsed Time: {0}", stop - start);
Console.WriteLine();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.