Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- 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";
- string temp;
- string[] list = str.Split(';');
- System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
- stopwatch.Start();
- stopwatch.Stop();
- stopwatch.Reset(); // first use of stopwatch can add extra time to mesurment
- stopwatch.Start();
- for (int i = 0; i < 100000; i++)
- {
- temp = str.Split(';').First(); //vs. str.Split(';')[0]
- // list.Where(x => x > 1).First() vs. list.Where(x => x > 1).ToList()[0]
- }
- stopwatch.Stop();
- Console.WriteLine("str.Split(';').First(); :\t\t\t {0}", stopwatch.ElapsedTicks);
- stopwatch.Reset();
- stopwatch.Start();
- for (int i = 0; i < 100000; i++)
- {
- temp = str.Split(';')[0];
- // list.Where(x => x > 1).First() vs. list.Where(x => x > 1).ToList()[0]
- }
- stopwatch.Stop();
- Console.WriteLine("str.Split(';')[0]; :\t\t\t\t {0}", stopwatch.ElapsedTicks);
- stopwatch.Reset();
- stopwatch.Start();
- for (int i = 0; i < 100000; i++)
- {
- temp = list.Where(x => x == "a").First(); //vs. list.Where(x => x > 1).ToList()[0]
- }
- stopwatch.Stop();
- Console.WriteLine("ist.Where(x => x == \"a\").First(); :\t\t {0}", stopwatch.ElapsedTicks);
- stopwatch.Reset();
- stopwatch.Start();
- for (int i = 0; i < 100000; i++)
- {
- temp = list.Where(x => x == "a").ToList()[0];
- }
- stopwatch.Stop();
- Console.WriteLine("list.Where(x => x == \"a\").ToList()[0]; :\t {0}", stopwatch.ElapsedTicks);
- stopwatch.Reset();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement