Measuring query time for CRUD methods from Northwind database using Entity Framework Core

42 views Asked by At

I try to measure a time for CRUD methods in Entity Framework Core for Northwind database. I work in Console App with C# in Visual Studio. I use Stopwatch() class, but something is wrong. During downloading a one record with selected OrderID the time is 3081ms and for all orders (1000 records) the time is 2092 ms...

The code looks like below:

  static void DownloadingOrders()
    {
        using (var northwindDb= new NorthwindContext())
        {
            Stopwatch watch = new Stopwatch();
            watch.Reset();
            watch.Start();;
         
            var orders = northwindDb.Orders
                .Where(o => o.OrderId >= 10248)
                .ToList();
            var milliseconds = watch.ElapsedMilliseconds;
            watch.Stop();

            foreach (var order in orders)
            {
              Console.WriteLine($"Order Id : {order.OrderId},  Employee ID: {order.EmployeeId} , Customer ID: {order.CustomerId}");
            }
           
            Console.WriteLine("The Time is: {0} ms", milliseconds);
        }

    }

The main idea is to test the performance of ORM tools and measure the time for CRUD operations, but the results it gets are not logical.

0

There are 0 answers