Skip to content

Instantly share code, notes, and snippets.

@masaru-b-cl
Last active March 16, 2016 08:41
Show Gist options
  • Save masaru-b-cl/b23b4891de5c45fbe63d to your computer and use it in GitHub Desktop.
Save masaru-b-cl/b23b4891de5c45fbe63d to your computer and use it in GitHub Desktop.
using System;
using System.Diagnostics;
using System.Linq;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var source = Enumerable.Range(1, 100000000).ToArray();
{
var sw = Stopwatch.StartNew();
var result = source
.Where(n => n % 2 == 0)
.Select(n => n * 2)
.ToArray();
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds); // 1204
}
{
var sw = Stopwatch.StartNew();
var result = source
// できたら並列処理してもいいよと伝える
.AsParallel()
// ここでむりくり並列化
.WithExecutionMode(ParallelExecutionMode.ForceParallelism)
.Where(n => n % 2 == 0)
.Select(n => n * 2)
.ToArray();
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds); // 975
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment