DongLiORM进行了第二次更新。
在性能方面改善了许多。
对一个4个字段,每个字段大约10个字符的表,查询大约每秒12万~16万条,新增/删除大约每秒1600~1800条。
测试环境:
    WinXP Sp2,奔4 2.9G,1.5GB内存, Sql Server Express.

不知这种测试算不算科学。欢迎大家拍砖。

测试用的类
UserItem.cs
using System;
using System.Collections.Generic;
using System.Collections;

namespace BUL.Security
{
    
/// <summary>
    
/// 实体类UserItem 。(属性说明自动提取数据库字段的描述信息)
    
/// </summary>
    
/// 

    [Serializable]
    [DongLiORM.BusinessAttribute(
"UsersView",new string[]{"UserID"},typeof(UserItem))]
    
public class UserItem:DongLiORM.BusinessObject
    
{
        
public UserItem()
        
{       
        }


        
private string _userid;
        
private string _username;
        
private string _pwd;
        
private string _email;
        
/// <summary>
        
/// 
        
/// </summary>

        public string UserID
        
{
            
set { _userid = value; }
            
get return _userid; }
        }

        
/// <summary>
        
/// 
        
/// </summary>

        public string UserName
        
{
            
set { _username = value; }
            
get return _username; }
        }

        
/// <summary>
        
/// 
        
/// </summary>

        public string Pwd
        
{
            
set { _pwd = value; }
            
get return _pwd; }
        }

        
/// <summary>
        
/// 
        
/// </summary>

        public string Email
        
{
            
set { _email = value; }
            
get return _email; }
        }



        
Indexer 
    }

}



测试用到窗体
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml.Serialization;
using System.IO;
using BUL.Security;
using DongLiORM;

namespace DongLiCreatorTest
{
    
public partial class Form1 : Form
    
{
        
public Form1()
        
{
            InitializeComponent();
        }


        
private void Form1_Load(object sender, EventArgs e)
        
{
            
this.comboBox1.SelectedIndex = 0;
        }


        
private void button1_Click(object sender, EventArgs e)
        
{
            
if(comboBox1.SelectedIndex==0)
                InsertTest();
            
else if(comboBox1.SelectedIndex==1)
                DeleteTest();
            
else
                SelectTest();
        }



        
const int MaxLong = 10000;
        
private void DeleteTest()
        
{   
            
long end = 0;

            BusinessAttribute Attr 
= BusinessAttribute.GetBusinessAttr(typeof(UserItem));
            UserItem AUser 
= null;
            
long Start2 = DateTime.Now.Ticks;
            
for (int i = 0, j = MaxLong; i < MaxLong; i++, j++)
            
{
                AUser 
= new UserItem();
                AUser.UserID 
= string.Format("U_ID{0}", j);
                AUser.UserName 
= string.Format("U_Name{0}", j);
                AUser.Pwd 
= string.Format("Pwd{0}", j);
                AUser.Email 
= string.Format("Email{0}", j);

                Attr.Writer.Delete(AUser);
            }

            end 
= DateTime.Now.Ticks;
            
long Span2 = end - Start2;
            label2.Text 
= (1.0F / ((float)Span2 / (float)TimeSpan.TicksPerSecond / (float)MaxLong)).ToString();
           
// label2.Text = ((float)Span2 / (float)TimeSpan.TicksPerMillisecond).ToString();


            
long Start1 = DateTime.Now.Ticks;
            
string Sql = "Delete from  UsersView where UserID=@UserID and UserName=@UserName and Pwd=@Pwd and Email=@Email";
            
//SqlConnection con = new SqlConnection("server=.;UID=sa;PWD=cctqa;database=TQM_2007");
            con.Open();
            
for (int i = 0; i < MaxLong; i++)
            
{
                SqlParameter[] Params 
= new SqlParameter[4]
                
{
                    
new SqlParameter("@UserID",SqlDbType.VarChar,10),
                    
new SqlParameter("@UserName",SqlDbType.VarChar,50),
                    
new SqlParameter("@Pwd",SqlDbType.VarChar,50),
                    
new SqlParameter("@Email",SqlDbType.VarChar,255)
                }
;
                Params[
0].Value = string.Format("U_ID{0}", i);
                Params[
1].Value = string.Format("U_Name{0}",i);
                Params[
2].Value = string.Format("Pwd{0}", i);
                Params[
3].Value = string.Format("Email{0}", i);


                SqlCommand cm 
= new SqlCommand(Sql, con);
                
foreach (SqlParameter param in Params)
                    cm.Parameters.Add(param);
                cm.ExecuteNonQuery();
            }


            end 
= DateTime.Now.Ticks;
            
long Span1 = end - Start1;
            label1.Text 
= (1.0F / ((float)Span1 / (float)TimeSpan.TicksPerSecond / (float)MaxLong)).ToString();
            
//label1.Text = ((float)Span1 / (float)TimeSpan.TicksPerMillisecond).ToString();
            con.Close();
            
//con.Dispose();


            
if (Span1 > 0)
                MessageBox.Show(((
float)Span2 / (float)Span1).ToString());
        }


        
private void InsertTest()
        
{           
            UserItem AUser 
= null;
            BusinessAttribute Attr 
= BusinessAttribute.GetBusinessAttr(typeof(UserItem));
            
long Start1 = DateTime.Now.Ticks;
            
string Sql = "insert into UsersView(UserID,UserName,Pwd,Email) values(@UserID,@UserName,@Pwd,@Email)";
            
//SqlConnection con = new SqlConnection("server=.;UID=sa;PWD=cctqa;database=TQM_2007");
            con.Open();
            
for (int i = 0; i < MaxLong; i++)
            
{
                SqlParameter[] Params 
= new SqlParameter[4]
                
{
                    
new SqlParameter("@UserID",string.Format("U_ID{0}",i)),
                    
new SqlParameter("@UserName",string.Format("U_Name{0}",i)),
                    
new SqlParameter("@Pwd",string.Format("Pwd{0}",i)),
                    
new SqlParameter("@Email",string.Format("Email{0}",i))
                }
;
                SqlCommand cm 
= new SqlCommand(Sql, con);
                
foreach (SqlParameter param in Params)
                    cm.Parameters.Add(param);
                cm.ExecuteNonQuery();
            }

           
            
long end = DateTime.Now.Ticks;
            
long Span1 = end - Start1;
            label1.Text 
= (1.0F / ((float)Span1 / (float)TimeSpan.TicksPerSecond / (float)MaxLong)).ToString();
            
//label1.Text = ((float)Span1 / (float)TimeSpan.TicksPerMillisecond).ToString();
            con.Close();
            
//con.Dispose();


            
long Start2 = DateTime.Now.Ticks;
            
for (int i = 0, j = MaxLong; i < MaxLong; i++, j++)
            
{
                AUser 
= new UserItem();
                AUser.UserID 
= string.Format("U_ID{0}", j);
                AUser.UserName 
= string.Format("U_Name{0}", j);
                AUser.Pwd 
= string.Format("Pwd{0}", j);
                AUser.Email 
= string.Format("Email{0}", j);

                Attr.Writer.Insert(AUser);
            }

            end 
= DateTime.Now.Ticks;
            
long Span2 = end - Start2;
            label2.Text 
= (1.0F / ((float)Span2 / (float)TimeSpan.TicksPerSecond / (float)MaxLong)).ToString();
            
//label2.Text = ((float)Span2 / (float)TimeSpan.TicksPerMillisecond).ToString();

            
if (Span1 > 0)
                MessageBox.Show(((
float)Span2 / (float)Span1).ToString());
        }

        SqlConnection con 
= new SqlConnection("server=.;UID=sa;PWD=cctqa;database=TQM_2007");

        
private void SelectTest()
        
{            
            con.Open();

            
long end = 0;
            
long Start2 = DateTime.Now.Ticks;
            BusinessAttribute Attr 
= BusinessAttribute.GetBusinessAttr(typeof(UserItem));
            
//            List<UserItem> Users = DBWR.Instance.GetDataThroughReader<UserItem>("Select * from UsersView", null);
            
//            label2.Text = (1.0F / ((float)Span2 / (float)TimeSpan.TicksPerSecond / (float)Users.Count)).ToString();
            UserItem[] Users = (UserItem[])Attr.Reader.GetDataByCondition("");
            end 
= DateTime.Now.Ticks;
            
long Span2 = end - Start2;
            label2.Text 
= (1.0F / ((float)Span2 / (float)TimeSpan.TicksPerSecond / (float)Users.Length)).ToString();
            
//label2.Text = ((float)Span2 / (float)TimeSpan.TicksPerMillisecond).ToString();
       
  
            UserItem AUser 
= null;
            
long Start1 = DateTime.Now.Ticks;
            
string Sql = "select * from UsersView";
           
            SqlCommand cmd 
= new SqlCommand(Sql, con);
            SqlDataReader reader 
= cmd.ExecuteReader();

            List
<UserItem> UserList = new List<UserItem>();
            
while (reader.Read()) 
            
{
                
//AUser = ParseARow<UserItem>(row1);
                AUser = new UserItem();
                AUser.UserID 
= (string)reader["UserID"];
                AUser.UserName 
= (string)reader["UserName"];
                AUser.Pwd 
= (string)reader["Pwd"];
                AUser.Email 
= (string)reader["Email"];

                UserList.Add(AUser);

                
//foreach (DataColumn c in table.Columns)
                
//{
                
//    AUser[c.ColumnName] = row1[c];
                
//}
            }

            reader.Close();
            cmd.Dispose();
            con.Close();
            

            end 
= DateTime.Now.Ticks;
            
long Span1 = end - Start1;
            label1.Text 
= (1.0F / ((float)Span1 / (float)TimeSpan.TicksPerSecond / (float)UserList.Count)).ToString();
            
//label1.Text = ((float)Span1 / (float)TimeSpan.TicksPerMillisecond).ToString();
            
          
//  con.Dispose();                              

            
if (Span1 > 0)
                MessageBox.Show(((
float)Span2 / (float)Span1).ToString());
        }


        
private static T ParseARow<T>(DataRow row1) where T:UserItem,new()
        
{
            T AUser 
= new T();
            
//foreach (DataColumn c in row1.Table.Columns)
            
//    AUser[c.ColumnName] = row1[c];
            AUser.UserID = row1["UserID"].ToString();
            AUser.UserName 
= row1["UserName"].ToString();
            AUser.Pwd 
= row1["Pwd"].ToString();
            AUser.Email 
= row1["Email"].ToString();
            
return AUser;
        }

    }

}

posted on 2007-07-16 22:38  永红  阅读(722)  评论(10)    收藏  举报