Last active
March 16, 2016 08:41
-
-
Save masaru-b-cl/b23b4891de5c45fbe63d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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