DataTalbe性能测试

None.gif using  System;
None.gif
using  System.Collections.Generic;
None.gif
using  System.Text;
None.gif
using  System.Data;
None.gif
None.gif
namespace  dtTest
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
class Program
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
static void Main(string[] args)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DataTable dt 
= new DataTable();
InBlock.gif            dt.Columns.Add(
"a"typeof(int));
InBlock.gif            dt.Columns.Add(
"b"typeof(string));
InBlock.gif            dt.Columns.Add(
"c"typeof(string));
InBlock.gif
InBlock.gif            
for (int i = 0; i < 1000000; i++)//1 million
ExpandedSubBlockStart.gifContractedSubBlock.gif
            dot.gif{
InBlock.gif                DataRow row 
= dt.NewRow();
InBlock.gif                row[
"a"= 0;
InBlock.gif                row[
"b"= "2";
InBlock.gif                row[
"c"= "3";
InBlock.gif                dt.Rows.Add(row);
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
//begin test
InBlock.gif
InBlock.gif            
//test1
InBlock.gif
            long tick = System.DateTime.Now.Ticks;
InBlock.gif            DataRow[] rows 
= dt.Select("a=0");
InBlock.gif            System.Console.WriteLine((System.DateTime.Now.Ticks 
- tick));
InBlock.gif
InBlock.gif            
//test2
InBlock.gif
            tick = System.DateTime.Now.Ticks;
InBlock.gif            StringBuilder sb 
= new StringBuilder();
InBlock.gif            
//dt2 = dt.Clone();
InBlock.gif
            for (int i = 0; i < dt.Rows.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (dt.Rows[i][0].ToString() == "0")
InBlock.gif                    sb.Append(dt.Rows[i][
0].ToString());
ExpandedSubBlockEnd.gif            }

InBlock.gif            System.Console.WriteLine((System.DateTime.Now.Ticks 
- tick));
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
behindme(43161308) 14:03:42
2比1快一倍。
behindme(43161308) 14:04:01
返回的东西不一样,可能觉得没可比性
behindme(43161308) 14:04:52
但如果把test2改成用新一DataTable加入,就在复制到另一个DataTable中,这样1比2快10倍
behindme(43161308) 14:06:01
另外不小心说明一个问题,StringBuiler比string在处理字符串的优势,用string,机子差点跑死掉

转载于:https://www.cnblogs.com/mazei/archive/2006/07/20/455517.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值