SQLite和SQl-Server2005简单对比
本次测试的数据量是60000条数据
分别在两个DB的数据库中创建相同结的表:
1 CREATE TABLE t_pincode
2 (
3 auto_no int IDENTITY(1,1) NOT NULL,
4 pin_code varchar(50),
5 batch_no varchar(50),
6 code_status int NULL
7 )
分别插入600000条数据进去,下面进行查询数据的性能对比:
SQLiteDB类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SQLite;
namespace DataTool
{
public class SQLiteDB
{
public void GetData()
{
SQLiteConnection conn = new SQLiteConnection();
conn.ConnectionString = "data source = d:\\mydb.bby";
conn.Open();
//SQLiteTransaction tran = conn.BeginTransaction();
SQLiteCommand command = conn.CreateCommand();
//try
//{
command.CommandType = CommandType.Text;
command.CommandText = "select * from t_pincode";
SQLiteDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
int iCount = 0;
if (reader.HasRows)
{
while (reader.Read())
{
iCount++;
}
}
//tran.Commit();
reader.Close();
reader.Dispose();
conn.Close();
conn.Dispose();
Console.WriteLine(string.Format("SQLite记录数:{0}", iCount));
//}
//catch (Exception)
//{
// tran.Rollback();
//}
}
}
}
SQLServerDB类:
1
using System;2
using System.Collections.Generic;3
using System.Linq;4
using System.Text;5
using System.Data;6
using System.Data.SqlClient;7

8
namespace DataTool9


{10
public class SQLServerDB11

{12
public void GetData()13

{14
SqlConnection conn = new SqlConnection();15
conn.ConnectionString = "server=192.168.1.11;database=db_test_event;uid=db_test_event_user;pwd=0xBFBAE8B63072A7798E803AE9F7D4FFAA;pooling=true;max pool size=2000;";16
conn.Open();17

18
SqlCommand command = conn.CreateCommand();19

20
command.CommandType = CommandType.Text;21
command.CommandText = "select * from t_pincode with(nolock)";22

23
SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);24

25
int iCount = 0;26

27
if (reader.HasRows)28

{29
while (reader.Read())30

{31
iCount++;32
}33
}34

35
reader.Close();36
reader.Dispose();37
command.Dispose();38
conn.Close();39
conn.Dispose();40

41
Console.WriteLine(string.Format("SQL-Server记录数:{0}", iCount));42
43
}44

45
public void GetDataByProc()46

{47
SqlConnection conn = new SqlConnection();48
conn.ConnectionString = "server=192.168.1.11;database=db_test_event;uid=db_test_event_user;pwd=0xBFBAE8B63072A7798E803AE9F7D4FFAA;pooling=true;max pool size=2000;connection timeout=60;";49

50
conn.Open();51

52
SqlCommand command = conn.CreateCommand();53

54
command.CommandType = CommandType.StoredProcedure;55
command.CommandText = "tpp_test";56

57
SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);58

59
int iCount = 0;60

61
if (reader.HasRows)62

{63
while (reader.Read())64

{65
iCount++;66
}67
}68

69
reader.Close();70
reader.Dispose();71
command.Dispose();72
conn.Close();73
conn.Dispose();74

75
Console.WriteLine(string.Format("SQL-Server记录数:{0}", iCount));76
}77
}78
}79

以下是调试代码:
1
using System;2
using System.Collections.Generic;3
using System.Linq;4
using System.Text;5
using System.Xml;6
using System.Xml.Linq;7
using DataTool;8
using System.Diagnostics;9

10
namespace MyConsole11


{12
class Program13

{14
static void Main(string[] args)15

{16
Stopwatch watch2 = new Stopwatch();17
watch2.Start();18
SQLiteDB sqlite = new SQLiteDB();19
sqlite.GetData();20
watch2.Stop();21

22
Console.WriteLine(string.Format("sqlite花费的时间:{0}", watch2.ElapsedMilliseconds));23

24
Stopwatch watch1 = new Stopwatch();25
watch1.Start();26
SQLServerDB sqlserver = new SQLServerDB();27
sqlserver.GetDataByProc();28
watch1.Stop();29

30
Console.WriteLine(string.Format("sqlserver花费的时间:{0}", watch1.ElapsedMilliseconds));31

32
Console.ReadLine();33
}34
}35
}对比出来SQLite花费时间:462 SQL-Server花费时间:3281
这个只是一个简单的对比。可能中间有一些问题,欢迎大家指正。

浙公网安备 33010602011771号