小编use*_*781的帖子

C#TPL比C++ PPL更快?

我编写了一个非常简单的应用程序,它使用Fibonacci函数来比较TPL Parallel.ForEach 和PPL parallel_for_each,结果非常奇怪,在具有8个内核的PC上,c# c ++ 快11秒.

vs2010和2011预览都有相同的结果.

C#代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using System.Diagnostics;

namespace ConsoleApplication1
{
    class Program
    {

            static void Main(string[] args)
            {
                var ll = new ConcurrentQueue<Tuple<int, int>>();
                var a = new int[12] { 40, 41, 42, 43, 44, 45, 46, 47, 35, 25, 36, 37 };

                long elapsed = time_call(() =>
                {
                    Parallel.ForEach(a, (n) => { ll.Enqueue(new Tuple<int, int>(n, fibonacci(n))); });
                });

                Console.WriteLine("TPL C# …
Run Code Online (Sandbox Code Playgroud)

c++ c#-4.0

6
推荐指数
3
解决办法
2310
查看次数

标签 统计

c#-4.0 ×1

c++ ×1