VC++.net 真的没有用吗?

 C++ 真的没有用吗?
Microsoft .NET Framework中关注的是 vb.net,C#。C++ 真的没有用吗?
C++真的是明日黄花吗?

下文的C ++指托管C++,如果用win32 的C++和.net比就没有意义了,没有技术含量。

下面做个测试:

static void function1()
        {
            int i = 0, j = 0, a = 0;

            for (i = 0; i < 100000; i++)
                j += i;
        }
        static void function2()
        {
            int i = 0, j = 0;

            for (i = 0; i < 200000; i++)
                j = i;
        }
        static void Main(string[] args)
        {
            int i = 0, j = 0;
            for (i = 0; i < 100; i++)
                function1();
            for (i = 0; i < 50000; i++)
                function2();

          
        }
这样的代码 让C#跑 要7秒,注:VC++.net代码相似,就不列出。
如果让 C++跑2秒都不到!
变本加厉,全部i < 200000;
即for (i = 0; i < 200000; i++),丝毫不影响C++!

测试2:
排序 算法:

C++

namespace cdll {

 public ref class Class1
 {
 public:void sort(array<int> ^list)
     {
      int i,j;
      int temp;
      bool done=false;
      j=1;
      while((j<list->Length )&&(!done))
      {
       done=true;
       for(i=0;i<list->Length-j;i++)
       {
        if(list[i]>(list[i+1]))
        {
         done=false;
         temp =list[i];
         list[i]=list[i+1];
         list[i+1]=temp;
        }
       }
       j++;

      };
     }
 };
}

C#

using System;
using System.Collections.Generic;
using System.Text;

namespace ClassLibrary1
{

    public class bubblesorter
    {
        public void sort(int[] list)
        {
            int i, j, temp;
            bool done = false;
            j = 1;
            while ((j < list.Length ) && (!done))
            {
                done = true;
                for (i = 0; i < list.Length - j; i++)
                {
                    if (list[i] > list[i + 1])
                    {
                        done = false;
                        temp = list[i];
                        list[i] = list[i + 1];
                        list[i + 1] = temp;
                    }
                }
                j++;
            }
        }
    }
}

测试控制台:

static void Main(string[] args)
        {
            Random ran=new Random(); 
            int[] iarrary=new int[80000];
          
            System.Text.StringBuilder    s=new StringBuilder();
            int temp;
            for (int i = 0; i < 80000; i++)
            { iarrary[i] = ran.Next(100000);
            temp = iarrary[i];
        
                s.Append(" ");
                s.Append(iarrary[i].ToString ());
            }
            ClassLibrary1.bubblesorter  csb=new ClassLibrary1.bubblesorter ();
cdll.Class1 cpb = new cdll.Class1();
           
            System.IO.File.AppendAllText (@"c:/1.text",s.ToString()) ;   
           
            Console.WriteLine(DateTime.Now);
          // csb.sort(iarrary);  //  test C #

            cpb.sort(iarrary); // C ++
            Console.WriteLine(DateTime.Now);
            for (int i = 0; i < 80000; i++)
            {
             
                s.Append(" ");
                s.Append(iarrary[i].ToString());
            }
             System.IO.File.AppendAllText(@"c:/2.text",s.ToString()) ;
            Console.Read();
        }
输出:
C#
2007-10-13 12:22:13
2007-10-13 12:22:36
C++
2007-10-13 12:23:21
2007-10-13 12:23:45

可以看出冒泡排序(bubble)中C++和C #不分伯仲。
(注我测试过 不同语言 .dll调用 要多用1 s)

工具 :VC++ 2005 电脑cpu 奔腾D820 ,内存DDR2 667 1G,系统:windows2003(sp2),vista 最终版

你可能感兴趣的:(C++,.net,list,function,Microsoft,vc++)