public async ValueTask RunAsync(int runs = Config.Runs, int records = Config.Records) { Console.WriteLine("## Dapper Buffered Query Class and Record Async 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 = await DapperQuery.QueryAsync <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 = await DapperQuery.QueryAsync <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(); DapperPocoElapsedAsync = dapperPocoElapsedAvg; DapperPocoKbAsync = Kb(dapperPocoBytesAvg); DapperRecordElapsedAsync = dapperRecordAvg; DapperRecordKbAsync = Kb(dapperRecordBytesAvg); Console.WriteLine($"|**AVG**|**{DapperPocoElapsedAsync}**|**{DapperPocoKbAsync}**|**{DapperRecordElapsedAsync}**|**{DapperRecordKbAsync}**|"); Console.WriteLine(); Console.WriteLine("Finished."); Console.WriteLine(); }
public async ValueTask RunAsync(int runs = Config.Runs, int records = Config.Records) { var sw = new Stopwatch(); var query = GetQuery(records); Console.WriteLine("## Dapper Buffered Query and Iteration vs Norm Read and Iteration Async Tests"); Console.WriteLine(); Console.WriteLine("|#|Dapper Buffered Query|Dapper Buffered Iteration|Daper Buffered Total|Dapper Buffered Allocated KB|Norm Read|Norm Iteration|Norm Total|Norm Allocated KB|"); Console.WriteLine("|-|---------------------|-------------------------|--------------------|----------------------------|---------|--------------|----------|-----------------|"); var list = new List <long[]>(); for (int i = 0; i < runs; i++) { var values = new long[8]; sw.Reset(); sw.Start(); var dapperQuery = await DapperQuery.QueryAsync <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(); long dapperQueryBytes = GC.GetTotalMemory(false); //GC.GetAllocatedBytesForCurrentThread(); var dapperIterationElapsed = sw.Elapsed; values[1] = sw.Elapsed.Ticks; var dapperTotal = dapperQueryElapsed + dapperIterationElapsed; values[2] = dapperTotal.Ticks; values[3] = dapperQueryBytes; dapperQuery = null; GC.Collect(int.MaxValue, GCCollectionMode.Forced); sw.Reset(); sw.Start(); var normRead = connection.ReadAsync <PocoClass>(query); sw.Stop(); var normReadElapsed = sw.Elapsed; values[4] = sw.Elapsed.Ticks; sw.Reset(); sw.Start(); await foreach (var row in normRead) { // do something } sw.Stop(); long normReadBytes = GC.GetTotalMemory(false); //GC.GetAllocatedBytesForCurrentThread(); var normReadIteration = sw.Elapsed; var normTotal = normReadElapsed + normReadIteration; values[5] = sw.Elapsed.Ticks; values[6] = normTotal.Ticks; values[7] = normReadBytes; normRead = null; GC.Collect(int.MaxValue, GCCollectionMode.Forced); list.Add(values); Console.WriteLine($"|{i + 1}|{dapperQueryElapsed}|{dapperIterationElapsed}|{dapperTotal}|{Kb(dapperQueryBytes)}|{normReadElapsed}|{normReadIteration}|{normTotal}|{Kb(normReadBytes)}|"); } 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 dapperBytesAvg = (long)list.Select(v => v[3]).Average(); var normReadAvg = new TimeSpan((long)list.Select(v => v[4]).Average()); var normIterationAvg = new TimeSpan((long)list.Select(v => v[5]).Average()); var normTotalAvg = new TimeSpan((long)list.Select(v => v[6]).Average()); var normBytesAvg = (long)list.Select(v => v[7]).Average(); Console.WriteLine($"|**AVG**|**{dapperQueryAvg}**|**{dapperIterationAvg}**|**{dapperTotalAvg}**|**{Kb(dapperBytesAvg)}**|**{normReadAvg}**|**{normIterationAvg}**|**{normTotalAvg}**|**{Kb(normBytesAvg)}**|"); Console.WriteLine(); }