|
Imports System.Collections.Generic
Imports System.Text
Imports System.Data.SqlClient
Imports System.Data
Imports System.Reflection
Imports System.Reflection.Emit
Module Program
Sub Main()
Dim connection As SqlConnection = New SqlConnection("Data Source=localhost; Initial Catalog=SpikeDB;Integrated Security=True")
Dim command As SqlCommand = New SqlCommand("Select * From LoadSpike2", connection)
connection.Open()
LoadManually(command)
LoadUsingReflection(command)
LoadUsingDynamicCode(command)
connection.Close()
Console.WriteLine("Done!")
Console.Read()
End Sub
Sub LoadManually(ByVal command As SqlCommand)
Dim start As DateTime = DateTime.Now
Console.WriteLine("Start Manual Load: {0}", start)
Dim reader As SqlDataReader = command.ExecuteReader()
Dim builder As ManualBuilder = New ManualBuilder()
While reader.Read()
Dim person As Person = builder.Build(reader)
End While
reader.Close()
Dim done As DateTime = DateTime.Now
Console.WriteLine("Stop Manual Load: {0}", done)
Console.WriteLine("Elapsed Time: {0}", done - start)
Console.WriteLine()
End Sub
Sub LoadUsingReflection(ByVal command As SqlCommand)
Dim start As DateTime = DateTime.Now
Console.WriteLine("Start Reflection Load: {0}", start)
Dim reader As SqlDataReader = command.ExecuteReader()
Dim builder As ReflectionBuilder(Of Person) = ReflectionBuilder(Of Person).CreateBuilder(reader)
While reader.Read()
Dim person As Person = builder.Build(reader)
End While
reader.Close()
Dim done As DateTime = DateTime.Now
Console.WriteLine("Stop Reflection Load: {0}", done)
Console.WriteLine("Elapsed Time: {0}", done - start)
Console.WriteLine()
End Sub
Sub LoadUsingDynamicCode(ByVal command As SqlCommand)
Dim start As DateTime = DateTime.Now
Console.WriteLine("Start Dynamic Load: {0}", start)
Dim reader As SqlDataReader = command.ExecuteReader()
Dim builder As DynamicBuilder(Of Person) = DynamicBuilder(Of Person).CreateBuilder(reader)
While reader.Read()
Dim person As Person = builder.Build(reader)
End While
reader.Close()
Dim done As DateTime = DateTime.Now
Console.WriteLine("Stop Dynamic Load: {0}", done)
Console.WriteLine("Elapsed Time: {0}", done - start)
Console.WriteLine()
End Sub
End Module
|
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.