Ejemplo n.º 1
0
        private static void CompareSimpleQuery()
        {
            Stopwatch watch = new Stopwatch();

            for (int i = 0; i < 3; i++)
            {
                Console.WriteLine($" Iteration {i}");

                // With EF 6
                watch.Restart();
                using (var context = new EF6.StarWarsContext())
                {
                    context.People.ToList();
                }
                watch.Stop();
                var prevResult = watch.ElapsedMilliseconds;
                Console.WriteLine($"  - EF6.x:      {watch.ElapsedMilliseconds}ms");

                // With EF Core
                watch.Restart();
                using (var context = new EFCore.StarWarsContext(_options))
                {
                    context.People.ToList();
                }
                watch.Stop();
                Console.WriteLine($"  - EF Core:    {watch.ElapsedMilliseconds}ms");

                // Bottom line
                var improvement = (prevResult - watch.ElapsedMilliseconds) / (double)prevResult;
                Console.WriteLine($"  - Improvement:{improvement.ToString("P0")}");
                Console.WriteLine();
            }
        }
Ejemplo n.º 2
0
 public static void Warmup(bool clearData)
 {
     using (var context = new StarWarsContext())
     {
         context.People.FirstOrDefault();
         if (clearData && context.People.Any())
         {
             context.Database.ExecuteSqlCommand("delete dbo.Starships");
             context.Database.ExecuteSqlCommand("delete dbo.People");
         }
     }
 }
Ejemplo n.º 3
0
 internal static void LoadLotsOfData()
 {
     using (var context = new StarWarsContext())
     {
         context.Configuration.AutoDetectChangesEnabled = false;
         for (int i = 1; i < Program.TABLE_SIZE; i++)
         {
             context.People.Add(
                 new Person
             {
                 Name = $"Person #{i}",
             });
         }
         context.SaveChanges();
     }
 }