- using System;
- using System.Text;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
-
- namespace ConsoleApplication1
- {
- class Program
- {
- ///
- /// ListのSortメソッドとLINQのOrderByメソッドの速度検証
- ///
- ///
- static void Main(string[] args)
- {
- List list = new List();
-
- // 1000万件データ作成
- for (int i = 10000000; i > 0; i-- )
- {
- list.Add(i);
- }
-
- Stopwatch sw = new Stopwatch();
- sw.Start();
-
- list.Sort();
-
- sw.Stop();
- Console.WriteLine("Sortメソッド:" + sw.Elapsed + "秒");
-
-
-
-
- List list2 = new List();
-
- // 1000万件データ作成
- for (int i = 10000000; i > 0; i--)
- {
- list2.Add(i);
- }
-
- sw.Restart();
-
- IOrderedEnumerable tmp = list2.OrderBy(n => n);
-
- sw.Stop();
- Console.WriteLine("OrderByメソッド:" + sw.Elapsed + "秒");
-
-
-
-
- sw.Restart();
-
- list2 = tmp.ToList();
-
- sw.Stop();
- Console.WriteLine("IOrderedEnumerableをListに変換:" + sw.Elapsed + "秒");
-
-
- Console.ReadLine();
- }
- }
- }
|