关于ORM性能测试

[ 2007-07-26 10:07:01 | 作者: progame ]
文字大小: | |
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导致它的性能极大的降低了
评论Feed 评论Feed: /feed.asp?q=comment&id=928

这篇日志没有评论.

发表
表情图标
[smile] [confused] [cool] [cry]
[eek] [angry] [wink] [sweat]
[lol] [stun] [razz] [redface]
[rolleyes] [sad] [yes] [no]
[heart] [star] [music] [idea]
UBB代码
转换链接
表情图标
悄悄话
用户名:   密码:   (非注册用户不需要输入密码) 注册?
验证码(不区分大小写) * 请输入验证码