Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ added new benchmarks for comparison to manual mapping #13

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 63 additions & 3 deletions MapDataReader.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,72 @@ public void MapDatareader_ViaDapper()
}

[Benchmark]
public void MapDataReader_ViaMapaDataReader()
public void MapDataReader_ViaMapDataReader()
{
var dr = _dt.CreateDataReader();
var list = dr.ToTestClass();
}

[Benchmark]
public void MapDataReader_ViaManualMap_CastMethods()
{
var dr = _dt.CreateDataReader();

var list = new List<TestClass>();
while (dr.Read())
{
list.Add(new TestClass
{
String1 = (string)dr["String1"],
String2 = (string)dr["String2"],
String3 = (string)dr["String3"],
Int = (int)dr["Int"],
Int2 = (int)dr["Int2"],
IntNullable = (int?)dr["IntNullable"]
});
}
}

[Benchmark]
public void MapDataReader_ViaManualMap_AsMethods()
{
var dr = _dt.CreateDataReader();

var list = new List<TestClass>();
while (dr.Read())
{
list.Add(new TestClass
{
String1 = dr["String1"] as string,
String2 = dr["String2"] as string,
String3 = dr["String3"] as string,
Int = dr["Int"] as int? ?? 0,
Int2 = dr["Int2"] as int? ?? 0,
IntNullable = dr["IntNullable"] as int?
});
}
}

[Benchmark]
public void MapDataReader_ViaManualMap_GetMethods()
{
var dr = _dt.CreateDataReader();

var list = new List<TestClass>();
while (dr.Read())
{
list.Add(new TestClass
{
String1 = dr.GetString(0),
String2 = dr.GetString(1),
String3 = dr.GetString(2),
Int = dr.GetInt32(3),
Int2 = dr.GetInt32(4),
IntNullable = dr.GetInt32(5) // this wouldn't work if the value is null though, this is just for benchmarking
});
}
}

static DataTable _dt;

[GlobalSetup]
Expand Down Expand Up @@ -99,8 +159,8 @@ public class TestClass
public string String1 { get; set; }
public string String2 { get; set; }
public string String3 { get; set; }
public string Int { get; set; }
public string Int2 { get; set; }
public int Int { get; set; }
public int Int2 { get; set; }
public int? IntNullable { get; set; }
}
}