Following from a comment on IsDbNull performance, I thought I would measure how the performance of IsDBNull.
http://weblogs.asp.net/justin_rogers/archive/2004/04/11/111151.aspx
Original test
This was the optimised access code from test 3 of the previous entry http://www.noelwatson.com/blog/PermaLink,guid,e93c0b50-233e-47d9-b3cf-bfacf754af05.aspx while (reader.Read()) { logDetails = (String)reader[0]; logTime =(DateTime)reader[1]; } taking around 8.3 seconds for 100 iterations
This was the optimised access code from test 3 of the previous entry
http://www.noelwatson.com/blog/PermaLink,guid,e93c0b50-233e-47d9-b3cf-bfacf754af05.aspx
while (reader.Read())
{ logDetails = (String)reader[0]; logTime =(DateTime)reader[1];
}
taking around 8.3 seconds for 100 iterations
1. IsDbNull()
{ if (!reader.IsDBNull(0)) { logDetails = (String)reader[0]; } if (!reader.IsDBNull(1)) { logTime =(DateTime)reader[1]; } } The duration of the experiment has increased dramtically to over 13 seconds.
{ if (!reader.IsDBNull(0)) { logDetails = (String)reader[0]; } if (!reader.IsDBNull(1)) { logTime =(DateTime)reader[1]; }
The duration of the experiment has increased dramtically to over 13 seconds.
2. Comparing to System.DBNull.Value
while (reader.Read()) { if (reader[0]!=System.DBNull.Value) { logDetails = (String)reader[0]; } if (reader[1]!=System.DBNull.Value) { logTime =(DateTime)reader[1]; }}
This test is quicker (approx 20%) and I think this is the 20% the article was referring to. However, as can be seen in the screendump, the number of calls to get_item has increased. Storing the value in a local variable will solve this
3. Storing result in local variable
while (reader.Read()) { detailsNullCheck = reader[0]; if (detailsNullCheck!=System.DBNull.Value) { logDetails = (String)detailsNullCheck; } timeNullCheck = reader[1]; if (timeNullCheck!=System.DBNull.Value) { logTime =(DateTime)timeNullCheck; } }
{ detailsNullCheck = reader[0]; if (detailsNullCheck!=System.DBNull.Value) { logDetails = (String)detailsNullCheck; } timeNullCheck = reader[1]; if (timeNullCheck!=System.DBNull.Value) { logTime =(DateTime)timeNullCheck; }
This value is approximately the same as the original test in the previous entry - checking for null values should not be an overhead.
Theme design by Jelle Druyts
Pick a theme: BlogXP calmBlue Candid Blue dasBlog Discreet Blog Blue Elegante essence Just Html MadsSimple Mobile Mono Movable Radio Blue Movable Radio Heat nautica022 orangeCream Portal Project84 Project84Grass Slate Sound Waves Tricoleur useit.com Voidclass2
Powered by: newtelligence dasBlog 1.9.6264.0
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2009, Noel Watson Consulting Ltd.
E-mail