zoukankan      html  css  js  c++  java
  • 基本类型泛型(一)


        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泛型基础结构
  • 相关阅读:
    mysql查看锁表情况
    利用xtrabackup备份mysql数据库
    /proc/sys/vm/参数
    linux的sysctl基本配置
    python计算apache总内存
    ip_conntrack table full dropping packet错误的解决方法
    apachetop 实时监控apache指定日志
    mysql大表myisam的导入
    编译安装php5.5和php-fpm
    tshark 抓包分析
  • 原文地址:https://www.cnblogs.com/tenghoo/p/1209921.html
Copyright © 2011-2022 走看看