基本类型--泛型(一)


    public static class Program {
        
public static void Main() {
            ValueTypeTest();
            ReferenceTypeTest();
            Console.ReadLine();
        }

        
private static void ValueTypeTest() {
            
const Int32 count = 10000000;
            
using (new OperatorTimer("泛型值类型:List<Int32>")) {
                List
<Int32> l = new List<int>();
                
for (int i = 0; i < count; i++{
                    l.Add(i);
                    Int32 x 
= l[i];
                }

                l 
= null;
            }

            
using (new OperatorTimer("非泛型值类型:ArrayList of Int32")) {
                ArrayList a 
= new ArrayList();
                
for (int i = 0; i < count; i++{
                    a.Add(i);
                    Int32 x 
= (Int32)a[i];
                }

                a 
= null;
            }

        }

        
private static void ReferenceTypeTest() {
            
const Int32 count = 10000000;
            
using (new OperatorTimer("泛型类型引用类型:List<String>")) {
                List
<String> l = new List<string>();
                
for (int i = 0; i < count; i++{
                    l.Add(
"X");
                    String x 
= l[i];
                }

                l 
= null;
            }

            
using (new OperatorTimer("非泛型类型引用类型:ArrayList of String")) {
                ArrayList a 
= new ArrayList();
                
for (int i = 0; i < count; i++{
                    a.Add(
"X");
                    String x 
= (String)a[i];
                }

                a 
= null;
            }

        }

    }

    
internal sealed class OperatorTimer : IDisposable {
        
private Int64 m_starttime;
        
private String m_text;
        
private Int32 m_collectionCount;
        
public OperatorTimer(String t) {
            PrepareForOperation();
            m_text 
= t;
            m_collectionCount 
= GC.CollectionCount(0);
            m_starttime 
= Stopwatch.GetTimestamp();
        }

        
public void Dispose() {
            Console.WriteLine(
"{0,6:###.00} seconds (GCs={1,3}){2}",
                (Stopwatch.GetTimestamp() 
- m_starttime) / (Double)Stopwatch.Frequency,
                GC.CollectionCount(
0- m_collectionCount,
                m_text);
        }

        
public static void PrepareForOperation() {
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
        }

    
    }
161FCL中的泛型

162WintellectPower Collections
 为了使CLR编程人员也能使用C++标准模板库的部分集合类,Wintellect制作了Power Collections库。可从Wintellect.com下载。
163泛型基础结构

posted on 2008-05-29 13:49 青羽 阅读(158) 评论(1)  编辑 收藏 所属分类: J 都是DotNetNCLR Via

评论

#1楼  2008-06-02 17:02 不妨沉迷      

不错 收藏   回复  引用  查看    


标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2008-05-29 13:53 编辑过


相关链接:
 

导航

公告

流量

website metrics V

与我联系

搜索

 

常用链接

留言簿

我参与的团队

随笔分类(211)

随笔档案(181)

文章分类(31)

收藏夹(146)

互联网

圈内

友情链接

园内

积分与排名

最新评论

阅读排行榜

评论排行榜