Exemplo n.º 1
0
        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"
                );
        }
Exemplo n.º 2
0
        public void Ado_RemoverPreco_test()
        {
            String nome = "Baldes", preco = "7,00", duracao = "00:50: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 = @valor AND duracao = @duracao ";

                    SqlParameter tipoParam    = new SqlParameter("@tipo", SqlDbType.VarChar, 32);
                    SqlParameter valorParam   = new SqlParameter("@valor", SqlDbType.Float);
                    SqlParameter duracaoParam = new SqlParameter("@duracao", SqlDbType.Time);

                    tipoParam.Value    = nome;
                    valorParam.Value   = preco;
                    duracaoParam.Value = duracao;

                    preco1.Parameters.Add(tipoParam);
                    preco1.Parameters.Add(valorParam);
                    preco1.Parameters.Add(duracaoParam);
                    SqlCommand preco2 = preco1.Clone();

                    SqlDataReader reader1 = preco1.ExecuteReader();
                    Assert.IsTrue(reader1.HasRows);
                    reader1.Dispose();

                    int row = cmd.RemoverPreco(nome, preco, duracao, validade);
                    Assert.AreEqual(1, row);

                    SqlDataReader reader2 = preco2.ExecuteReader();
                    Assert.IsFalse(reader2.HasRows);
                    reader2.Dispose();
                    tran.Complete();
                }
            }
        }