mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
反射+缓存性能优化,接近dapper
This commit is contained in:
@ -6,6 +6,8 @@ using Xunit;
|
||||
using Dapper;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
|
||||
namespace FreeSql.Tests.PerformanceTest {
|
||||
public class MySqlAdoTest {
|
||||
@ -143,6 +145,41 @@ namespace FreeSql.Tests.PerformanceTest {
|
||||
sb.AppendLine($"Elapsed: {time.Elapsed}; ToList Entity Counts: {t3.Count}; ORM: FreeSql*");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToListLimit10() {
|
||||
var sb = new StringBuilder();
|
||||
var time = new Stopwatch();
|
||||
|
||||
time.Restart();
|
||||
var dplist1Count = 0;
|
||||
var p1 = Parallel.For(1, 50, b => {
|
||||
List<xxx> dplist1 = new List<xxx>();
|
||||
for (var a = 0; a < 1000; a++) {
|
||||
using (var conn = g.mysql.Ado.MasterPool.Get()) {
|
||||
dplist1.AddRange(Dapper.SqlMapper.Query<xxx>(conn.Value, "select * from song limit 50").ToList());
|
||||
}
|
||||
}
|
||||
Interlocked.Exchange(ref dplist1Count, dplist1.Count);
|
||||
});
|
||||
while (p1.IsCompleted == false) ;
|
||||
time.Stop();
|
||||
sb.AppendLine($"Elapsed: {time.Elapsed}; Query Entity Counts: {dplist1Count}; ORM: Dapper");
|
||||
|
||||
|
||||
time.Restart();
|
||||
var t3Count = 0;
|
||||
var p3 = Parallel.For(1, 50, b => {
|
||||
List<xxx> t3 = new List<xxx>();
|
||||
for (var a = 0; a < 1000; a++) {
|
||||
t3.AddRange(g.mysql.Select<xxx>().Limit(50).ToList());
|
||||
}
|
||||
Interlocked.Exchange(ref t3Count, t3.Count);
|
||||
});
|
||||
while (p3.IsCompleted == false) ;
|
||||
time.Stop();
|
||||
sb.AppendLine($"Elapsed: {time.Elapsed}; ToList Entity Counts: {t3Count}; ORM: FreeSql*");
|
||||
}
|
||||
|
||||
[Table(Name = "song")]
|
||||
class xxx {
|
||||
public int Id { get; set; }
|
||||
|
Reference in New Issue
Block a user