Advertisement
Guest User

Untitled

a guest
Sep 1st, 2014
598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9.     class Program
  10.     {
  11.  
  12.         static void Main(string[] args)
  13.         {
  14.             string str = "q;w;e;r;t;y;u;i;o;p;a;s;d;f;g;h;j;k;l;z;x;c;v;b;n;m";
  15.             string temp;
  16.             string[] list = str.Split(';');
  17.  
  18.  
  19.  
  20.  
  21.  
  22.             System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
  23.  
  24.             stopwatch.Start();
  25.             stopwatch.Stop();
  26.             stopwatch.Reset(); // first use of stopwatch can add extra time to mesurment
  27.  
  28.             stopwatch.Start();
  29.             for (int i = 0; i < 100000; i++)
  30.             {
  31.                 temp = str.Split(';').First(); //vs. str.Split(';')[0]
  32.  
  33.                 // list.Where(x => x > 1).First() vs. list.Where(x => x > 1).ToList()[0]
  34.             }
  35.             stopwatch.Stop();
  36.             Console.WriteLine("str.Split(';').First(); :\t\t\t {0}", stopwatch.ElapsedTicks);
  37.             stopwatch.Reset();
  38.  
  39.  
  40.             stopwatch.Start();
  41.             for (int i = 0; i < 100000; i++)
  42.             {
  43.                 temp = str.Split(';')[0];
  44.  
  45.                 // list.Where(x => x > 1).First() vs. list.Where(x => x > 1).ToList()[0]
  46.             }
  47.             stopwatch.Stop();
  48.             Console.WriteLine("str.Split(';')[0]; :\t\t\t\t {0}", stopwatch.ElapsedTicks);
  49.             stopwatch.Reset();
  50.  
  51.  
  52.             stopwatch.Start();
  53.             for (int i = 0; i < 100000; i++)
  54.             {
  55.                 temp = list.Where(x => x == "a").First(); //vs. list.Where(x => x > 1).ToList()[0]
  56.             }
  57.             stopwatch.Stop();
  58.             Console.WriteLine("ist.Where(x => x == \"a\").First(); :\t\t {0}", stopwatch.ElapsedTicks);
  59.             stopwatch.Reset();
  60.  
  61.  
  62.             stopwatch.Start();
  63.             for (int i = 0; i < 100000; i++)
  64.             {
  65.                 temp = list.Where(x => x == "a").ToList()[0];
  66.             }
  67.             stopwatch.Stop();
  68.             Console.WriteLine("list.Where(x => x == \"a\").ToList()[0]; :\t {0}", stopwatch.ElapsedTicks);
  69.             stopwatch.Reset();
  70.  
  71.  
  72.  
  73.  
  74.             Console.ReadKey();
  75.  
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement