J
Jorge
Hello all! I'm making some performance test with the SqlDataReader
class, specifically with the different options to retrieve the values.
Some of these options are :
reader("FieldName")
reader(2) 'using field indexes
reader.GetInt32(2)
Documentations says that the first method is not a good option because
is slower than the others, but my test tell me the opposite. I'm
testing with the Northwind database and the "Order Details" table
(2,000 records). This is my code :
------------------------
....
Dim cmd As New SqlCommand("SELECT * FROM [order details]", conn)
Dim reader As SqlDataReader = cmd.ExecuteReader
Dim begin, end As DateTime
begin = DateTime.Now
'I read two fields: ProductID (index 1) and Quantity (index 3)
Dim field1 As Integer
Dim field2 As Short
Do While reader.Read()
c1 = CInt(reader("ProductID"))
c2 = CShort(reader("Quantity"))
'c1 = CInt(reader(1))
'c2 = CShort(reader(3))
'c1 = reader.GetInt32(1)
'c2 = reader.GetInt16(3)
Loop
end = DateTime.Now
Dim TS As TimeSpan = New System.TimeSpan(end.Ticks - begin.Ticks)
Console.WriteLine(TS.Milliseconds)
------------------------
Making three times each test I get this:
First method = 47, 31, 31
Second method = 31, 31, 15
Third method = 140, 46, 62
What is going on? I'm confused!
Thanks!
Roberto
class, specifically with the different options to retrieve the values.
Some of these options are :
reader("FieldName")
reader(2) 'using field indexes
reader.GetInt32(2)
Documentations says that the first method is not a good option because
is slower than the others, but my test tell me the opposite. I'm
testing with the Northwind database and the "Order Details" table
(2,000 records). This is my code :
------------------------
....
Dim cmd As New SqlCommand("SELECT * FROM [order details]", conn)
Dim reader As SqlDataReader = cmd.ExecuteReader
Dim begin, end As DateTime
begin = DateTime.Now
'I read two fields: ProductID (index 1) and Quantity (index 3)
Dim field1 As Integer
Dim field2 As Short
Do While reader.Read()
c1 = CInt(reader("ProductID"))
c2 = CShort(reader("Quantity"))
'c1 = CInt(reader(1))
'c2 = CShort(reader(3))
'c1 = reader.GetInt32(1)
'c2 = reader.GetInt16(3)
Loop
end = DateTime.Now
Dim TS As TimeSpan = New System.TimeSpan(end.Ticks - begin.Ticks)
Console.WriteLine(TS.Milliseconds)
------------------------
Making three times each test I get this:
First method = 47, 31, 31
Second method = 31, 31, 15
Third method = 140, 46, 62
What is going on? I'm confused!
Thanks!
Roberto