小编use*_*240的帖子

为什么LINQ(c#)与Seq(f#)之间存在性能差异

我做了非常简单的C#和F#测试程序.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace ConsoleApplication2
{
    class Program
    {
        static int Remainder(int num)
        {
            return num % 2;
        }
        static int SumOfremainders(IEnumerable<int> list)
        {
            var sum = 0;
            foreach (var num in list)
            {
                sum += Remainder(num);
            }
            return sum;
        }

        static void Main(string[] args)
        {
            Stopwatch sw = new Stopwatch();
            var nums = Enumerable.Range(1, 10000000);
            sw.Start();
            var a = SumOfremainders(nums);
            sw.Stop();
            Console.WriteLine("Duration " + (sw.ElapsedMilliseconds));
            Console.WriteLine("Sum of remainders: {0}", a);
        }
    }
} …
Run Code Online (Sandbox Code Playgroud)

c# linq performance f#

8
推荐指数
1
解决办法
584
查看次数

标签 统计

c# ×1

f# ×1

linq ×1

performance ×1