using system;
using system.collections;
using system.componentmodel;
using system.data;
using system.drawing;
using system.text;
using system.windows.forms;
namespace nhibernatetestui
{
public partial class orderfrm : form
{
public orderfrm()
{
initializecomponent();
}
nhibernatetest.order order = new nhibernatetest.order();
/**//// <summary>
/// 使用nhibernate hql方式查询
/// </summary>
private void btnnhload_click( object sender, eventargs e )
{
string stroutput = "";
// 测试加载数据时间
datetime dtstart = system.datetime.now;
ilist orders = order.loadallbynhibernate(); // 使用nhibernate hql方式查询
datetime dtend = system.datetime.now;
timespan ts = dtend - dtstart;
stroutput += "nhibernate hql方式 : "
+ orders.count + " 条记录, 加载时间(ms) : "
+ ts.totalmilliseconds;
// 测试绑定数据时间
dtstart = system.datetime.now;
this.dgvorders.datasource = orders;
dtend = system.datetime.now;
ts = dtend - dtstart;
stroutput += " 绑定ilist时间 : " + ts.totalmilliseconds;
console.writeline( stroutput );
}
/**//// <summary>
/// 使用ado.net dbdataadapter方式查询
/// </summary>
private void btnadoload_click( object sender, eventargs e )
{
string stroutput = "";
// 测试加载数据时间
datetime dtstart = system.datetime.now;
datatable dtorders = order.loadallbyad.net(); // 使用ado.net dbdataadapter方式查询
datetime dtend = system.datetime.now;
timespan ts = dtend - dtstart;
stroutput += "ado.net dbdataadapter方式 : "
+ dtorders.rows.count + " 条记录; 加载时间(ms) : "
+ ts.totalmilliseconds;
// 测试绑定数据时间
dtstart = system.datetime.now;
this.dgvorders.datasource = dtorders;
dtend = system.datetime.now;
ts = dtend - dtstart;
stroutput += " 绑定ilist时间 : " + ts.totalmilliseconds;
console.writeline( stroutput );
}
}
}
运行后界面如下:
在界面两个按钮点击多次后,两者的查询时间稳定,可以作为比较。下面是输出:
nhibernate :select order0_.orderid as orderid, order0_.shippeddate as shippedd4_, order0_.shippostalcode as shippos10_, order0_.requireddate as required3_, order0_.shipcountry as shipcou11_, order0_.shipvia as shipvia, order0_.orderdate as orderdate, order0_.shipaddress as shipaddr7_, order0_.shipregion as shipregion, order0_.shipname as shipname, order0_.shipcity as shipcity, order0_.customerid as customerid, order0_.freight as freight, order0_.employeeid as employeeid from orders order0_
nhibernate hql方式 : 830 条记录, 加载时间(ms) : 3334.7952 绑定ilist时间 : 70.1008
nhibernate :select order0_.orderid as orderid, order0_.shippeddate as shippedd4_, order0_.shippostalcode as shippos10_, order0_.requireddate as required3_, order0_.shipcountry as shipcou11_, order0_.shipvia as shipvia, order0_.orderdate as orderdate, order0_.shipaddress as shipaddr7_, order0_.shipregion as shipregion, order0_.shipname as shipname, order0_.shipcity as shipcity, order0_.customerid as customerid, order0_.freight as freight, order0_.employeeid as employeeid from orders order0_
nhibernate hql方式 : 830 条记录, 加载时间(ms) : 3304.752 绑定ilist时间 : 70.1008
nhibernate :select order0_.orderid as orderid, order0_.shippeddate as shippedd4_, order0_.shippostalcode as shippos10_, order0_.requireddate as required3_, order0_.shipcountry as shipcou11_, order0_.shipvia as shipvia, order0_.orderdate as orderdate, order0_.shipaddress as shipaddr7_, order0_.shipregion as shipregion, order0_.shipname as shipname, order0_.shipcity as shipcity, order0_.customerid as customerid, order0_.freight as freight, order0_.employeeid as employeeid from orders order0_
nhibernate hql方式 : 830 条记录, 加载时间(ms) : 3354.824 绑定ilist时间 : 80.1152
ado.net dbdataadapter方式 : 830 条记录; 加载时间(ms) : 40.0576 绑定ilist时间 : 80.1152
ado.net dbdataadapter方式 : 830 条记录; 加载时间(ms) : 40.0576 绑定ilist时间 : 90.1296
ado.net dbdataadapter方式 : 830 条记录; 加载时间(ms) : 30.0432 绑定ilist时间 : 90.1296
nhibernate :select order0_.orderid as orderid, order0_.shippeddate as shippedd4_, order0_.shippostalcode as shippos10_, order0_.requireddate as required3_, order0_.shipcountry as shipcou11_, order0_.shipvia as shipvia, order0_.orderdate as orderdate, order0_.shipaddress as shipaddr7_, order0_.shipregion as shipregion, order0_.shipname as shipname, order0_.shipcity as shipcity, order0_.customerid as customerid, order0_.freight as freight, order0_.employeeid as employeeid from orders order0_
nhibernate hql方式 : 830 条记录, 加载时间(ms) : 3334.7952 绑定ilist时间 : 70.1008
ado.net dbdataadapter方式 : 830 条记录; 加载时间(ms) : 50.072 绑定ilist时间 : 90.1296
另外在网上找了一下关于nhibernate性能的讨论的有,
http://kevin-y.cnblogs.com/archive/2006/02/08/327164.html
http://wljcan.cnblogs.com/archive/2005/05/14/155495.aspx
很少,希望能有已经做过nhibernate考量的高手提供点路子,非常感谢。
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器