关于ORM性能测试的一点意见
2007-07-26 09:49
309 查看
ADO.NET、NBear和NHibernate和IbatisNet简单读写性能比较
再续NBear性能测试:ADO.NET, NBearV3, NHibernateV1, NBearLite, NBearLite+NBearMapping性能比较
我总觉得这个例子里对数据库的操作不能反应实际运用情况
希望大家能写成这样的测试
load all categories, and traverse it's products
for(...)
{
category cat = new category(id)
load(cat)
double sum = 0
foreaach(product p in cat.products)
{
sum += p.amount
}
// find entity in cat's products by id and by index
cat.products[id].productname = cat.products[5].productname
}
写测试
// created
category cat = new category(id)
cat.xxx = xxx
....
for (....) // add some products
{
cat.products.add(new product(id))
}
save(cat)
// update
cat = new catetory(id)
load(cat)
cat.xxx = xxx
foreach(product p in cat.products)
{
p.xxx = xxx
}
save(cat)
// delete cat and it's products
delete(cat)
说明:
以实际情况做参考, category以100条数据为测试, 每个category下有30条product
不知大家用ORM的情况如何, 就我本人来说, 有这样几点是主要的:
根据class 生成数据库, 在项目初期可频繁更新迭代数据库的schema, 要做的只是修改domain class
类型化的entity和property便于在上述迭代中重构, 不至于隐藏的sql string中出现和schema不符的对象
关系的使用, cat.products["001"] cat.products.add(new product("002")) p.category.name role.users user.roles
类型化的查询 product.category.name == "abc" & product.price > 100f
附上现有测试我的结果:
Read Performance Comparison(ms)
Repeat Times:2 ADO.NET:46 NHibernate:668 TBP:205 NBear:1246
Repeat Times:4 ADO.NET:94 NHibernate:215 TBP:132 NBear:1631
Repeat Times:10 ADO.NET:207 NHibernate:462 TBP:318 NBear:4083
Repeat Times:20 ADO.NET:413 NHibernate:852 TBP:641 NBear:8155
Repeat Times:30 ADO.NET:622 NHibernate:1260 TBP:951 NBear:12245
Write Performance Comparison(ms)
Repeat Times:40 ADO.NET:204 NHibernate:292 TBP:272 NBear:556
Repeat Times:80 ADO.NET:417 NHibernate:608 TBP:504 NBear:1016
Repeat Times:200 ADO.NET:1102 NHibernate:1533 TBP:1565 NBear:2731
Repeat Times:400 ADO.NET:2617 NHibernate:3861 TBP:2796 NBear:5516
Repeat Times:600 ADO.NET:4011 NHibernate:5079 TBP:4148 NBear:9527
实际上在读这个测试很不公平, 我的TBP太占便宜了, 为什么这样说呢
EntityList<Products> products = s.GetList<Products>();
EntityList<Categories> categories = s.GetList<Categories>();
EntityList<Customers> customers = s.GetList<Customers>();
我的EntityList是在需要时才构造entity的, 如果要这样来一下:
foreach (Products p in products)
{
p.productName = p.productName;
}
那么TBP的速度马上就和NBear相当了, 在这不得不PF NH的构造实体集合的速度
而在写测试上, 为什么TBP和Ado.net如此接近,? 实际上是Ado.Net的测试写得有问题
SqlHelper.ExecuteNonQuery(conn, CommandType.Text, "update Products set UnitPrice = 16.8 where ProductID = " + productID.ToString() );
对于多次循环执行的这样一句SQL, 没有使用DBCommand.PrepaidCommand和Parameter导致它的性能极大的降低了
再续NBear性能测试:ADO.NET, NBearV3, NHibernateV1, NBearLite, NBearLite+NBearMapping性能比较
我总觉得这个例子里对数据库的操作不能反应实际运用情况
希望大家能写成这样的测试
load all categories, and traverse it's products
for(...)
{
category cat = new category(id)
load(cat)
double sum = 0
foreaach(product p in cat.products)
{
sum += p.amount
}
// find entity in cat's products by id and by index
cat.products[id].productname = cat.products[5].productname
}
写测试
// created
category cat = new category(id)
cat.xxx = xxx
....
for (....) // add some products
{
cat.products.add(new product(id))
}
save(cat)
// update
cat = new catetory(id)
load(cat)
cat.xxx = xxx
foreach(product p in cat.products)
{
p.xxx = xxx
}
save(cat)
// delete cat and it's products
delete(cat)
说明:
以实际情况做参考, category以100条数据为测试, 每个category下有30条product
不知大家用ORM的情况如何, 就我本人来说, 有这样几点是主要的:
根据class 生成数据库, 在项目初期可频繁更新迭代数据库的schema, 要做的只是修改domain class
类型化的entity和property便于在上述迭代中重构, 不至于隐藏的sql string中出现和schema不符的对象
关系的使用, cat.products["001"] cat.products.add(new product("002")) p.category.name role.users user.roles
类型化的查询 product.category.name == "abc" & product.price > 100f
附上现有测试我的结果:
Read Performance Comparison(ms)
Repeat Times:2 ADO.NET:46 NHibernate:668 TBP:205 NBear:1246
Repeat Times:4 ADO.NET:94 NHibernate:215 TBP:132 NBear:1631
Repeat Times:10 ADO.NET:207 NHibernate:462 TBP:318 NBear:4083
Repeat Times:20 ADO.NET:413 NHibernate:852 TBP:641 NBear:8155
Repeat Times:30 ADO.NET:622 NHibernate:1260 TBP:951 NBear:12245
Write Performance Comparison(ms)
Repeat Times:40 ADO.NET:204 NHibernate:292 TBP:272 NBear:556
Repeat Times:80 ADO.NET:417 NHibernate:608 TBP:504 NBear:1016
Repeat Times:200 ADO.NET:1102 NHibernate:1533 TBP:1565 NBear:2731
Repeat Times:400 ADO.NET:2617 NHibernate:3861 TBP:2796 NBear:5516
Repeat Times:600 ADO.NET:4011 NHibernate:5079 TBP:4148 NBear:9527
实际上在读这个测试很不公平, 我的TBP太占便宜了, 为什么这样说呢
EntityList<Products> products = s.GetList<Products>();
EntityList<Categories> categories = s.GetList<Categories>();
EntityList<Customers> customers = s.GetList<Customers>();
我的EntityList是在需要时才构造entity的, 如果要这样来一下:
foreach (Products p in products)
{
p.productName = p.productName;
}
那么TBP的速度马上就和NBear相当了, 在这不得不PF NH的构造实体集合的速度
而在写测试上, 为什么TBP和Ado.net如此接近,? 实际上是Ado.Net的测试写得有问题
SqlHelper.ExecuteNonQuery(conn, CommandType.Text, "update Products set UnitPrice = 16.8 where ProductID = " + productID.ToString() );
对于多次循环执行的这样一句SQL, 没有使用DBCommand.PrepaidCommand和Parameter导致它的性能极大的降低了
相关文章推荐
- 140425关于性能测试的一点感悟
- 关于DB2的简单并行性能测试
- android ORM框架的性能简单测试(androrm vs ormlite)
- 谈一点关于内存和性能
- 性能测试和数据分析的一点总结
- 关于性能测试的通俗解释
- 关于测试机器磁盘性能
- 关于在Java程序当中创建对象等基本操作的性能测试
- 关于@autoreleasepool的性能测试及手动释放自动释放池
- 关于Linux系统性能瓶颈定位分析(一),Nginx状态页测试(待续)
- 关于性能测试的那些事
- 关于 C# 中 Dictionary与Hashtable的性能测试
- 关于泊松分布(系统性能测试并发用户估算理论)
- 关于性能测试
- 性能测试和数据分析的一点总结
- 关于微软软件的操作系统在中国公司的比较性能测试-后果有很多后门木马因为微软没有打开系统的两个功能
- 关于 直播流转码系统 性能测试经验总结【逐步完善】
- 关于Mybatis的Batch模式性能测试及结论
- 关于性能测试
- 关于Int自增字段和GUID字段的性能测试。只有测试,没有分析,呵呵