public async Task Test_EntityMapperPerformanceAsync(int index) { index++; IDatabase database = _mysql; var books = Mocker.GetBooks(5000); var trans = await _mysqlTransaction.BeginTransactionAsync <BookEntity>().ConfigureAwait(false); IEnumerable <BookEntity> re = await database.RetrieveAsync <BookEntity>(b => b.Deleted, trans).ConfigureAwait(false); await database.AddAsync(Mocker.GetBooks(1)[0], "", trans).ConfigureAwait(false); try { //await database.AddAsync<BookEntity>(books[0], "", trans); await database.BatchAddAsync(books, "x", trans).ConfigureAwait(false); await _mysqlTransaction.CommitAsync(trans).ConfigureAwait(false); } catch { await _mysqlTransaction.RollbackAsync(trans).ConfigureAwait(false); } Stopwatch stopwatch = new Stopwatch(); using MySqlConnection mySqlConnection = new MySqlConnection(_mysqlConnectionString); TypeHandlerHelper.AddTypeHandlerImpl(typeof(DateTimeOffset), new DateTimeOffsetTypeHandler(), false); //time = 0; int loop = 100; TimeSpan time0 = TimeSpan.Zero, time1 = TimeSpan.Zero, time2 = TimeSpan.Zero, time3 = TimeSpan.Zero; for (int cur = 0; cur < loop; ++cur) { await mySqlConnection.OpenAsync().ConfigureAwait(false); using MySqlCommand command0 = new MySqlCommand("select * from tb_bookentity limit 10000", mySqlConnection); var reader0 = await command0.ExecuteReaderAsync().ConfigureAwait(false); List <BookEntity> list1 = new List <BookEntity>(); List <BookEntity> list2 = new List <BookEntity>(); List <BookEntity> list3 = new List <BookEntity>(); int len = reader0.FieldCount; EntityPropertyDef[] propertyDefs = new EntityPropertyDef[len]; MethodInfo[] setMethods = new MethodInfo[len]; EntityDef definition = EntityDefFactory.GetDef <BookEntity>() !; for (int i = 0; i < len; ++i) { propertyDefs[i] = definition.GetPropertyDef(reader0.GetName(i)) !; setMethods[i] = propertyDefs[i].SetMethod; } Func <IDataReader, object> mapper1 = EntityMapperDelegateCreator.CreateToEntityDelegate(definition, reader0, 0, definition.FieldCount, false, Database.Engine.EngineType.MySQL); //Warning: �����Dapper��С��DateTimeOffset�Ĵ洢���ᶪʧoffset��Ȼ��ת����ʱ����ϵ���ʱ���offset Func <IDataReader, object> mapper2 = DataReaderTypeMapper.GetTypeDeserializerImpl(typeof(BookEntity), reader0); Stopwatch stopwatch1 = new Stopwatch(); Stopwatch stopwatch2 = new Stopwatch(); Stopwatch stopwatch3 = new Stopwatch(); while (reader0.Read()) { stopwatch1.Start(); object obj1 = mapper1(reader0); list1.Add((BookEntity)obj1); stopwatch1.Stop(); stopwatch2.Start(); object obj2 = mapper2(reader0); list2.Add((BookEntity)obj2); stopwatch2.Stop(); stopwatch3.Start(); BookEntity item = new BookEntity(); for (int i = 0; i < len; ++i) { EntityPropertyDef property = propertyDefs[i]; object?value = TypeConvert.DbValueToTypeValue(reader0[i], property, Database.Engine.EngineType.MySQL); if (value != null) { setMethods[i].Invoke(item, new object?[] { value }); } } list3.Add(item); stopwatch3.Stop(); } time1 += stopwatch1.Elapsed; time2 += stopwatch2.Elapsed; time3 += stopwatch3.Elapsed; await reader0.DisposeAsync().ConfigureAwait(false); command0.Dispose(); await mySqlConnection.CloseAsync().ConfigureAwait(false); } _output.WriteLine("Emit Coding : " + (time1.TotalMilliseconds / (loop * 1.0)).ToString(CultureInfo.InvariantCulture)); _output.WriteLine("Dapper : " + (time2.TotalMilliseconds / (loop * 1.0)).ToString(CultureInfo.InvariantCulture)); _output.WriteLine("Reflection : " + (time3.TotalMilliseconds / (loop * 1.0)).ToString(CultureInfo.InvariantCulture)); }