2

Dapper と Enterprise Library Data Access Access ブロックを比較して、ストアド プロシージャ経由でデータを取得します。Dapper を使用すると、全体的なパフォーマンスが約 40% 向上しますが、これは少し驚くべきことです。

ただし、反復を比較して IEnumerable(IDataRecord) と IEnumerable(dynamic) からデータを取得すると、IEnumerable(IDataRecord) の方が約 1 桁高速です。この動作は十分に理解されており、予期されていることですか、それとも何か間違っていることがありますか?

結果:

IEnumerable(IDataRecord) ここに画像の説明を入力

IEnumerable(dynamic) - dapperObject.propertyName を使用 ここに画像の説明を入力

ここで興味深いことに、dapperObject["propertyName"] を使用すると、パフォーマンスは IDataRecord と同等になります。私が期待していたものとはまったく違います。 ここに画像の説明を入力

プロファイリング コードの関連部分

using System;
using System.Collections.Generic;
using System.Linq;
using Dapper.DataAccess;
using System.Data;
using tophat;

namespace Dapper.TestRunner
{
    class Program
    {
        static void Main(string[] args)
        {
            var connectionString = "data source=WEBDBdev3,1866; User id=hsbmhw;Password=gEner4Y&M;Persist Security Info='true'; initial catalog=myhomeworks;";
            //The following uses Tophat to create a singleton connection instance.
            Database.Install<SqlServerConnectionFactory>(connectionString, ConnectionScope.ByRequest);
            DapperTest();
            DapperTest2();
            EnterpriseLibraryIDataRecordTest();

        }

        private static void DapperTest()
        {
            for (int i = 0; i < 100; i++)
            {
                IEnumerable<dynamic> users = MyRepository.GetUsersDapper();
                PopulateBusinessObjectsDynamic(users);
            }
        }

        private static void DapperTest2()
        {
            for (int i = 0; i < 100; i++)
            {
                IEnumerable<dynamic> users = MyRepository.GetUsersDapper();
                PopulateBusinessObjectsDynamic2(users);
            }
        }

        private static void EnterpriseLibraryIDataRecordTest()
        {
            for (int i = 0; i < 100; i++)
            {
                IEnumerable<IDataRecord> users = MyRepository.GetUsersEntlib();
                PopulateBusinessObjectsIDataRecord(users);
            }
        }

        private static void PopulateBusinessObjectsDynamic(IEnumerable<dynamic> users)
        {
            foreach (var user in users)
            {
                BusinessObject bo = new BusinessObject(user);
            }
        }

        private static void PopulateBusinessObjectsDynamic2(IEnumerable<dynamic> users)
        {
            foreach (var user in users)
            {
                BusinessObject bo = new BusinessObject(user);
            }
        }


        private static void PopulateBusinessObjectsIDataRecord(IEnumerable<IDataRecord> users)
        {
            foreach (var user in users)
            {
                BusinessObject bo = new BusinessObject(user);
            }
        }
    }



    public class BusinessObject
    {

        public DateTime CreateDate { get; set; }
        public String CreateDateString { get; set; }
        public String FirstName { get; set; }
        public bool IsApproved { get; set; }
        public bool IsLockedOut { get; set; }
        public DateTime LastActivityDate { get; set; }
        public DateTime LastLoginDate { get; set; }
        public String LastName {get;set;}
        public String Organization{get;set;}
        public int OrganizationId{get;set;}
        public int PersonId{get;set;}
        public String ProfileLastUpdatedBy{get;set;}
        public DateTime ProfileLastUpdatedDate{get;set;}
        public String RoleName{get;set;}
        public long RowNumber{get;set;}
        public int TotalCount{get;set;}
        public Guid UserId{get;set;}
        public string UserName {get;set;}
        public string UserStatus{get;set;}

        public BusinessObject(dynamic user)
        {
            CreateDate=user.CreateDate;
            CreateDateString = user.CreateDateString;
            FirstName = user.FirstName;
            IsApproved = user.IsApproved;
            IsLockedOut = user.IsLockedOut;
            LastActivityDate= user.LastActivityDate;
            LastLoginDate = user.LastLoginDate;
            LastName = user.LastName;
            Organization = user.organization;
            OrganizationId=user.organization_id;
            PersonId = user.party_id;
            ProfileLastUpdatedBy = user.ProfileLastUpdatedBy;
            ProfileLastUpdatedDate = user.ProfileLastUpdatedDate;
            RoleName = user.RoleName;
            RowNumber = user.RowNumber;
            TotalCount = user.TotalCount;
            UserId = user.UserId;
            UserName= user.UserName;
            UserStatus = user.UserStatus;
        }

        public BusinessObject(bool x, dynamic user)
        {
            CreateDate = user["CreateDate"];
            CreateDateString = user["CreateDateString"];
            FirstName = user["FirstName"];
            IsApproved = user["IsApproved"];
            IsLockedOut = user["IsLockedOut"];
            LastActivityDate = user["LastActivityDate"];
            LastLoginDate = user["LastLoginDate"];
            LastName = user["LastName"];
            Organization = user["organization"];
            OrganizationId = user["organization_id"];
            PersonId = user["party_id"];
            ProfileLastUpdatedBy = user["ProfileLastUpdatedBy"];
            ProfileLastUpdatedDate = user["ProfileLastUpdatedDate"];
            RoleName = user["RoleName"];
            RowNumber = user["RowNumber"];
            TotalCount = user["TotalCount"];
            UserId = user["UserId"];
            UserName = user["UserName"];
            UserStatus = user["UserStatus"];
        }

        public BusinessObject(IDataRecord user)
        {
            CreateDate = (DateTime)user["CreateDate"];
            CreateDateString = (string)user["CreateDateString"];
            FirstName = (string)user["FirstName"];
            IsApproved = (bool)user["IsApproved"];
            IsLockedOut = (bool)user["IsLockedOut"];
            LastActivityDate = (DateTime)user["LastActivityDate"];
            LastLoginDate = (DateTime)user["LastLoginDate"];
            LastName = (string)user["LastName"];
            Organization = (string)user["organization"];
            OrganizationId = (int)user["organization_id"];
            PersonId = (int)user["party_id"];
            ProfileLastUpdatedBy = (string)user["ProfileLastUpdatedBy"];
            ProfileLastUpdatedDate = (DateTime)user["ProfileLastUpdatedDate"];
            RoleName = (string)user["RoleName"];
            RowNumber = (long)user["RowNumber"];
            TotalCount = (int)user["TotalCount"];
            UserId = (Guid)user["UserId"];
            UserName = (string)user["UserName"];
            UserStatus = (string)user["UserStatus"];
        }
    }
}
4

1 に答える 1