using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using Microsoft.Data.SqlClient;
using System.Diagnostics;
public static List<BenchmarkResult> BenchmarkResults = new List<BenchmarkResult>();
public static void Main()
using (var context = new EntityContext())
context.Database.EnsureCreated();
var clockSaveChanges = new Stopwatch();
var clockBulkUpdate = new Stopwatch();
using (var context = new EntityContext())
var customers = context.Customers.ToList();
clockSaveChanges.Start();
BenchmarkResults.Add(new BenchmarkResult() { Action = "SaveChanges (EF)", Entities = customers.Count, Performance = clockSaveChanges.ElapsedMilliseconds + " ms" });
using (var context = new EntityContext())
var customers = context.Customers.ToList();
context.BulkUpdate(customers);
BenchmarkResults.Add(new BenchmarkResult() { Action = "BulkUpdate (EF Extensions)", Entities = customers.Count, Performance = clockBulkUpdate.ElapsedMilliseconds + " ms" });
FiddleHelper.WriteTable(BenchmarkResults);
public static void JustInTime_Compile()
using (var context = new EntityContext())
var customers = context.Customers.ToList();
using (var context = new EntityContext())
var customers = context.Customers.ToList();
context.BulkUpdate(customers);
using (var context = new EntityContext())
context.BulkDelete(context.Customers);
public static List<Customer> GenerateCustomers(int count)
var list = new List<Customer>();
for(int i = 0; i < count; i++)
list.Add(new Customer() { Code = "Code_" + i, FirstName = "FirstName_" + i, LastName = "LastName_" + i });
using (var context = new EntityContext())
context.BulkInsert(list, options => options.AutoMapOutputDirection = false);
public class EntityContext : DbContext
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
optionsBuilder.UseSqlServer(new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()));
base.OnConfiguring(optionsBuilder);
public DbSet<Customer> Customers { get; set; }
public int CustomerID { get; set; }
public string Code { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Column1 { get; set; }
public string Column2 { get; set; }
public string Column3 { get; set; }
public string Column4 { get; set; }
public string Column5 { get; set; }
public string Column6 { get; set; }
public string Column7 { get; set; }
public string Column8 { get; set; }
public string Column9 { get; set; }
public class BenchmarkResult
public string Action { get; set; }
public int Entities { get; set; }
public string Performance { get; set; }