using System.Collections.Generic;
using System.Diagnostics;
using System.Data.SqlClient;
public static List<BenchmarkResult> BenchmarkResults = new List<BenchmarkResult>();
public static void Main()
var customers = GenerateCustomers(1000);
var clockBulkInsert = new Stopwatch();
using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()))
using (var bulk = new BulkOperation<Customer>(connection))
bulk.DestinationTableName = "Customers";
bulk.AutoMapOutputDirection = false;
bulk.BulkInsert(customers);
BenchmarkResults.Add(new BenchmarkResult() { Action = "BulkInsert (EF Extensions)", Entities = customers.Count, Performance = clockBulkInsert.ElapsedMilliseconds + " ms" });
FiddleHelper.WriteTable(BenchmarkResults);
public static void JustInTime_Compile()
var customers = GenerateCustomers(20);
using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()))
using (var bulk = new BulkOperation<Customer>(connection))
bulk.DestinationTableName = "Customers";
bulk.AutoMapOutputDirection = false;
bulk.BulkInsert(customers);
bulk.BulkDelete(customers);
public static List<Customer> GenerateCustomers(int count)
var list = new List<Customer>();
for(int i = 0; i < count; i++)
list.Add(new Customer() { Name = "Customer_" + i, Description = "Description_" + i, IsActive = i % 2 == 0 });
public static void GenerateDatabase()
using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()))
using (var command = connection.CreateCommand())
[CustomerID] [INT] IDENTITY(1,1) NOT NULL,
[Name] [NVARCHAR](MAX) NULL,
[Description] [NVARCHAR](MAX) NULL,
[IsActive] [BIT] NOT NULL,
CONSTRAINT [PK_Customers] PRIMARY KEY CLUSTERED
command.ExecuteNonQuery();
public int CustomerID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public Boolean IsActive { get; set; }
public class BenchmarkResult
public string Action { get; set; }
public int Entities { get; set; }
public string Performance { get; set; }