1 int t_rowNum = 10000 ;
2 int t_column = 1000 ;
3 Console.WriteLine("测试创建一个{0}行{1}列的表需要多少时间:",t_rowNum,t_column);
4 DataTable dt = new DataTable();
5 DateTime t1 = DateTime.Now ;
6 DataColumn dc ;
7 for( int c= 0 ;c< t_column ; c++ )
8 {
9 dc = new DataColumn("c"+c);
10
11 dt.Columns.Add( dc );
12
13 }
14 DateTime t2 = DateTime.Now ;
15
16 Console.WriteLine("列已经创建,耗时:"+(t2-t1).Milliseconds+"毫秒");
17
18 DateTime t3=DateTime.Now ;
19 DateTime t4 =DateTime.Now;
20
21 DateTime t5=DateTime.Now ;
22 DataRow dr ;
23 for(int r=0;r<t_rowNum;r++)
24 {
25 if ( r == 0 )
26 t3 = DateTime.Now;
27 dr = dt.NewRow();
28 for( int c=0;c<t_column;c++)
29 {
30 dr[c]="hahshisadadaihdiashd"+c+":"+r ;
31
32 }
33 dt.Rows.Add(dr);
34
35 if ( r== 0 )
36 {
37 t4 = DateTime.Now ;
38 Console.WriteLine("正在创建行,预计耗时:"+((t4-t3).Milliseconds*t_rowNum)+"毫秒");
39 }
40 }
41 DateTime t6 =DateTime.Now;
42
43 Console.WriteLine("行已经创建,耗时:"+((t6-t5).TotalSeconds)+"秒");
44
45 Console.ReadLine();
这个还是要耗用900多M内存~
2 int t_column = 1000 ;
3 Console.WriteLine("测试创建一个{0}行{1}列的表需要多少时间:",t_rowNum,t_column);
4 DataTable dt = new DataTable();
5 DateTime t1 = DateTime.Now ;
6 DataColumn dc ;
7 for( int c= 0 ;c< t_column ; c++ )
8 {
9 dc = new DataColumn("c"+c);
10
11 dt.Columns.Add( dc );
12
13 }
14 DateTime t2 = DateTime.Now ;
15
16 Console.WriteLine("列已经创建,耗时:"+(t2-t1).Milliseconds+"毫秒");
17
18 DateTime t3=DateTime.Now ;
19 DateTime t4 =DateTime.Now;
20
21 DateTime t5=DateTime.Now ;
22 DataRow dr ;
23 for(int r=0;r<t_rowNum;r++)
24 {
25 if ( r == 0 )
26 t3 = DateTime.Now;
27 dr = dt.NewRow();
28 for( int c=0;c<t_column;c++)
29 {
30 dr[c]="hahshisadadaihdiashd"+c+":"+r ;
31
32 }
33 dt.Rows.Add(dr);
34
35 if ( r== 0 )
36 {
37 t4 = DateTime.Now ;
38 Console.WriteLine("正在创建行,预计耗时:"+((t4-t3).Milliseconds*t_rowNum)+"毫秒");
39 }
40 }
41 DateTime t6 =DateTime.Now;
42
43 Console.WriteLine("行已经创建,耗时:"+((t6-t5).TotalSeconds)+"秒");
44
45 Console.ReadLine();