BenchmarkDotNet
BenchmarkDotNet copied to clipboard
extremely slow when benchmark test involves sqlconnection and sql datareader
hi, I want to compare some EDM lib's performance (i.e. automapper.data and dapper). So I created a quite simple test:
using (var conn = new SqlConnection(@"xxxx"))
{
conn.Open();
using (var cmd = new SqlCommand("select top 100 citicode, codetype, mexcode, sedolcode, isincode, unitcode, fundcode from sometable with(nolock)", conn))
{
for (int i = 0; i < loop; i++)
{
cmd.CommandType = System.Data.CommandType.Text;
using (var reader = cmd.ExecuteReader())
{
var result = _mapper.Map<IDataReader, IEnumerable<fxunit>>(reader);
}
}
}
}
If I run this code in a console, this code runs really quick, but if I decorate it with a [Benchmark] attribute and run it with BenchmarkDotNet, this becomes really slow to finish.
Is there a reason for this behaviour?
Hi @daxu7509,
BenchmarkDotNet executes each benchmark multiple times in the same process. Could you please try to do the same with your console application? Just wrap the code with for (int iter = 0; iter < 5; iter++) and measure the time of each iteration using Stopwatch (it's enough to notice the difference between 370us and 60s). I believe you should observe the same effect that you have with BenchmarkDotNet.
No response for the provided hint, closing