diff --git a/MapDataReader.Benchmarks/Program.cs b/MapDataReader.Benchmarks/Program.cs index d402e0c..898095e 100644 --- a/MapDataReader.Benchmarks/Program.cs +++ b/MapDataReader.Benchmarks/Program.cs @@ -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(); + 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(); + 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(); + 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] @@ -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; } } } \ No newline at end of file