public void Run(int runs = Config.Runs, int records = Config.Records) { Console.WriteLine("## Dapper Buffered Query Class and Record Tests"); Console.WriteLine(); Console.WriteLine("|#|Class Elapsed Sec|Class Allocated KB|Record Elapsed Sec|Record Allocated KB|"); Console.WriteLine("|-|-----------------|------------------|------------------|-------------------|"); var sw = new Stopwatch(); var query = GetQuery(records); var list = new List <long[]>(); for (int i = 0; i < runs; i++) { var values = new long[4]; GC.Collect(int.MaxValue, GCCollectionMode.Forced); sw.Reset(); sw.Start(); var dapperPoco = DapperQuery.Query <PocoClass>(connection, query); sw.Stop(); long dapperPocoBytes = GC.GetTotalMemory(false); //GC.GetAllocatedBytesForCurrentThread(); var dapperPocoElapsed = sw.Elapsed; values[0] = dapperPocoElapsed.Ticks; values[1] = dapperPocoBytes; dapperPoco = null; GC.Collect(int.MaxValue, GCCollectionMode.Forced); sw.Reset(); sw.Start(); var dapperRecord = DapperQuery.Query <Record>(connection, query); sw.Stop(); long dapperRecordBytes = GC.GetTotalMemory(false); //GC.GetAllocatedBytesForCurrentThread(); var dapperRecordElapsed = sw.Elapsed; values[2] = dapperRecordElapsed.Ticks; values[3] = dapperRecordBytes; dapperRecord = null; GC.Collect(int.MaxValue, GCCollectionMode.Forced); list.Add(values); Console.WriteLine($"|{i + 1}|{dapperPocoElapsed}|{Kb(dapperPocoBytes)}|{dapperRecordElapsed}|{Kb(dapperRecordBytes)}|"); } var dapperPocoElapsedAvg = new TimeSpan((long)list.Select(v => v[0]).Average()); var dapperPocoBytesAvg = (long)list.Select(v => v[1]).Average(); var dapperRecordAvg = new TimeSpan((long)list.Select(v => v[2]).Average()); var dapperRecordBytesAvg = (long)list.Select(v => v[3]).Average(); DapperPocoElapsedSync = dapperPocoElapsedAvg; DapperPocoKbSync = Kb(dapperPocoBytesAvg); DapperRecordElapsedSync = dapperRecordAvg; DapperRecordKbSync = Kb(dapperRecordBytesAvg); Console.WriteLine($"|**AVG**|**{DapperPocoElapsedSync}**|**{DapperPocoKbSync}**|**{DapperRecordElapsedSync}**|**{DapperRecordElapsedSync}**|"); Console.WriteLine(); Console.WriteLine("Finished."); Console.WriteLine(); }
public void Run(int runs = Config.Runs, int records = Config.Records) { var sw = new Stopwatch(); var query = GetQuery(records); Console.WriteLine("## Dapper Query and Iteration (Buffered and Unbuffered) vs Norm Read and Iteration Tests"); Console.WriteLine(); Console.WriteLine("|#|Dapper Buffered Query|Dapper Buffered Iteration|Daper Buffered Total|Dapper Unbuffered Query|Dapper Unbuffered Iteration|Daper Unbuffered Total|Norm Read|Norm Iteration|Norm Total|"); Console.WriteLine("|-|---------------------|-------------------------|--------------------|-----------------------|---------------------------|----------------------|---------|--------------|----------|"); var list = new List <long[]>(); for (int i = 0; i < runs; i++) { var values = new long[9]; sw.Reset(); sw.Start(); var dapperQuery = DapperQuery.Query <PocoClass>(connection, query); sw.Stop(); var dapperQueryElapsed = sw.Elapsed; values[0] = sw.Elapsed.Ticks; sw.Reset(); sw.Start(); foreach (var row in dapperQuery) { // do something } sw.Stop(); var dapperIterationElapsed = sw.Elapsed; values[1] = sw.Elapsed.Ticks; var dapperTotal = dapperQueryElapsed + dapperIterationElapsed; values[2] = dapperTotal.Ticks; dapperQuery = null; GC.Collect(int.MaxValue, GCCollectionMode.Forced); sw.Reset(); sw.Start(); var dapperUnbufferedQuery = DapperQuery.Query <PocoClass>(connection, query, buffered: false); sw.Stop(); var dapperUnbufferedQueryElapsed = sw.Elapsed; values[3] = sw.Elapsed.Ticks; sw.Reset(); sw.Start(); foreach (var row in dapperUnbufferedQuery) { // do something } sw.Stop(); var dapperUnbufferedIterationElapsed = sw.Elapsed; values[4] = sw.Elapsed.Ticks; var dapperUnbufferedTotal = dapperUnbufferedQueryElapsed + dapperUnbufferedIterationElapsed; values[5] = dapperUnbufferedTotal.Ticks; dapperUnbufferedQuery = null; GC.Collect(int.MaxValue, GCCollectionMode.Forced); sw.Reset(); sw.Start(); var normRead = connection.Read <PocoClass>(query); sw.Stop(); var normReadElapsed = sw.Elapsed; values[6] = sw.Elapsed.Ticks; sw.Reset(); sw.Start(); foreach (var row in normRead) { // do something } sw.Stop(); var normReadIteration = sw.Elapsed; values[7] = sw.Elapsed.Ticks; normRead = null; var normTotal = normReadElapsed + normReadIteration; values[8] = normTotal.Ticks; GC.Collect(int.MaxValue, GCCollectionMode.Forced); list.Add(values); Console.WriteLine($"|{i + 1}|{dapperQueryElapsed}|{dapperIterationElapsed}|{dapperTotal}|{dapperUnbufferedQueryElapsed}|{dapperUnbufferedIterationElapsed}|{dapperUnbufferedTotal}|{normReadElapsed}|{normReadIteration}|{normTotal}|"); } var dapperQueryAvg = new TimeSpan((long)list.Select(v => v[0]).Average()); var dapperIterationAvg = new TimeSpan((long)list.Select(v => v[1]).Average()); var dapperTotalAvg = new TimeSpan((long)list.Select(v => v[2]).Average()); var dapperBufferedQueryAvg = new TimeSpan((long)list.Select(v => v[3]).Average()); var dapperBufferedIterationAvg = new TimeSpan((long)list.Select(v => v[4]).Average()); var dapperBufferedTotalAvg = new TimeSpan((long)list.Select(v => v[5]).Average()); var normReadAvg = new TimeSpan((long)list.Select(v => v[6]).Average()); var normIterationAvg = new TimeSpan((long)list.Select(v => v[7]).Average()); var normTotalAvg = new TimeSpan((long)list.Select(v => v[8]).Average()); DapperQueryAvg = dapperQueryAvg; DapperIterationAvg = dapperIterationAvg; DapperTotalAvg = dapperTotalAvg; DapperBufferedQueryAvg = dapperBufferedQueryAvg; DapperBufferedIterationAvg = dapperBufferedIterationAvg; DapperBufferedTotalAvg = dapperBufferedTotalAvg; NormReadAvg = normReadAvg; NormIterationAvg = normIterationAvg; NormTotalAvg = normTotalAvg; Console.WriteLine($"|**AVG**|**{dapperQueryAvg}**|**{dapperIterationAvg}**|**{dapperTotalAvg}**|**{dapperBufferedQueryAvg}**|**{dapperBufferedIterationAvg}**|**{dapperBufferedTotalAvg}**|**{normReadAvg}**|**{normIterationAvg}**|**{normTotalAvg}**|"); Console.WriteLine(); Console.WriteLine("Finished."); Console.WriteLine(); }