小编Gan*_*ula的帖子

无法重现:C++ Vector性能优于C#List性能

在微软的BUILD大会上,Herb Sutter解释说C++有"真正的阵列"和C#/ Java语言没有相同或类似的东西.

我被卖掉了.您可以在http://channel9.msdn.com/Events/Build/2014/2-661观看完整的演讲

这是幻灯片的快照,他描述了这一点.http://i.stack.imgur.com/DQaiF.png

但是我想知道我会有多大的不同.

所以我编写了非常天真的测试程序,它从一个文件中创建一个大的字符串向量,行数从5个字符到50个字符不等.

链接到文件:

www (dot) dropbox.com/s/evxn9iq3fu8qwss/result.txt
Run Code Online (Sandbox Code Playgroud)

然后我按顺序访​​问它们.

我在C#和C++中都做过这个练习.

注意:我做了一些修改,删除了循环中的复制,如建议的那样.感谢您帮助我理解Real数组.

在C#中,我使用了List和ArrayList,因为不推荐使用ArrayList而使用List.

以下是戴尔Core i7处理器的戴尔笔记本电脑的结果:

count       C# (List<string>)   C# (ArrayList)     C++   

1000           24 ms              21 ms             7 ms       
10000         214 ms             213 ms            64 ms     
100000  2 sec 123 ms       2 sec 125 ms           678 ms    
Run Code Online (Sandbox Code Playgroud)

C#代码:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace CSConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            int count;
            bool …
Run Code Online (Sandbox Code Playgroud)

c# c++ performance vector

20
推荐指数
2
解决办法
3975
查看次数

标签 统计

c# ×1

c++ ×1

performance ×1

vector ×1