Performance test with data reader

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
 
B

bruce barker

not nealry enough test cases or control of condtions.

you should turn pooling off. turn each test at least 100 times, open
connection once, prime it and use the same conection for all tests.
aletnating test between passes would also e a good idea.


-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top