public void CompareADO_VS_EF_Round2() { Stopwatch sw = new Stopwatch(); int MAX_RUNS = 50; int ignore = 0; // Test EF speed for InserirPreco followed by RemoverPreco long EFBestTime = int.MaxValue; sw.Start(); for (int i = 0; i < MAX_RUNS; i++) { Stopwatch sw2 = new Stopwatch(); sw2.Start(); using (EfCommand cmd = new EfCommand()) { // inserir ignore = cmd.InserirPreco("Baldes", "9999" + i, "23:00:00", "3000-01-01 00:00:00"); } using (EfCommand cmd = new EfCommand()) { // remover o que inserimos ignore = cmd.RemoverPreco("Baldes", "9999" + i, "23:00:00", "3000-01-01 00:00:00"); } sw2.Stop(); EFBestTime = (sw2.ElapsedTicks < EFBestTime) ? sw2.ElapsedTicks : EFBestTime; } sw.Stop(); long EFtime = sw.ElapsedMilliseconds; // Test ADO.NET speed for InserirPreco followed by RemoverPreco sw.Reset(); sw.Start(); long ADOdotNETBestTime = int.MaxValue; for (int i = 0; i < MAX_RUNS; i++) { Stopwatch sw2 = new Stopwatch(); sw2.Start(); using (AdoCommand cmd = new AdoCommand()) { // inserir ignore = cmd.InserirPreco("Baldes", "9999" + i, "23:00:00", "3000-01-01 00:00:00"); } using (AdoCommand cmd = new AdoCommand()) { // remover o que inserimos ignore = cmd.RemoverPreco("Baldes", "9999" + i, "23:00:00", "3000-01-01 00:00:00"); } sw2.Stop(); ADOdotNETBestTime = (sw2.ElapsedTicks < ADOdotNETBestTime) ? sw2.ElapsedTicks : ADOdotNETBestTime; } sw.Stop(); long ADOdotNETtime = sw.ElapsedMilliseconds; Console.WriteLine( "EF -> Total time: " + EFtime + "ms Best time: " + EFBestTime + "ticks" + "\nADO.NET -> Total time: " + ADOdotNETtime + "ms Best time: " + ADOdotNETBestTime + "ticks" ); }
public void Ado_InserirPreco_test() { String tipo = "Baldes", valor = "20,0", duracao = "2:00:00", validade = "3000-10-10 10:00:00"; using (TransactionScope tran = new TransactionScope()) { using (AdoCommand cmd = new AdoCommand()) { SqlCommand preco1 = cmd.GetConnection().CreateCommand(); preco1.CommandText = "SELECT * FROM Preco WHERE tipo = '" + tipo + "' AND valor = " + 20; //SqlParameter tipoParam = new SqlParameter("@tipo", SqlDbType.VarChar, 32); //SqlParameter valorParam = new SqlParameter("@valor",SqlDbType.Float); //SqlParameter duracaoParam = new SqlParameter("@duracao",SqlDbType.Time); //SqlParameter validadeParam = new SqlParameter("@validade",SqlDbType.DateTime); // //tipoParam.Value = tipo; //valorParam.Value = valor; //duracaoParam.Value = duracao; //validadeParam.Value = validade; // //preco1.Parameters.Add(tipoParam); //preco1.Parameters.Add(valorParam); //preco1.Parameters.Add(duracaoParam); //preco1.Parameters.Add(validadeParam); SqlCommand preco2 = preco1.Clone(); SqlDataReader reader1 = preco1.ExecuteReader(); Assert.IsFalse(reader1.HasRows); reader1.Dispose(); int row = cmd.InserirPreco(tipo, valor, duracao, validade); Assert.AreEqual(1, row); SqlDataReader reader2 = preco2.ExecuteReader(); Assert.IsTrue(reader2.HasRows); reader2.Dispose(); tran.Complete(); } } }