1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
private static void comparePerf()
{
string connectionString = @"Application Name=TestPerf;Server=XXXXX\SQL2005;Database=XXXX;Trusted_Connection=True;";
string sql = "select * from XXXXXXX";
DateTime a = DateTime.Now;
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = sql;
int readerLineCount = 0;
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
object[] values = new object[reader.FieldCount];
for (int i = 0; i < reader.FieldCount; i++)
{
values[i] = reader[i];
}
readerLineCount++;
}
reader.Close();
}
}
connection.Close();
}
DateTime b = DateTime.Now;
DataSet dataSet = new DataSet();
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = sql;
SqlDataAdapter adapter = new SqlDataAdapter(command);
adapter.Fill(dataSet);
}
connection.Close();
}
DateTime c = DateTime.Now;
StringBuilder sb = new StringBuilder();
sb.AppendFormat("Temps Lecture datareader {0} ms", (b - a).TotalMilliseconds);
sb.AppendLine();
sb.AppendFormat("Temps Lecture dataSet {0} ms", (c - b).TotalMilliseconds);
sb.AppendLine();
Console.WriteLine(sb);
Console.ReadKey();
} |
Partager