Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1.         private const int max = 10485760;
  2.  
  3.         private static void Main()
  4.         {            
  5.             int[] numbers = new int[max];
  6.  
  7.             Console.WriteLine("Starting number loading with ConsoleHelper");
  8.             Stopwatch timer = Stopwatch.StartNew();
  9.             using (ConsoleHelper console = new ConsoleHelper())
  10.             {
  11.                 for (int i = 0; i < max; i++)
  12.                 {
  13.                     numbers[i] = console.NextInt();
  14.                 }
  15.             }
  16.             timer.Stop();
  17.  
  18.             Console.WriteLine("Time taken to load all values: " + timer.Elapsed.TotalSeconds + "s");
  19.             Console.WriteLine("Starting number loading with Regular Console");
  20.  
  21.             TextReader std = Console.In;
  22.             numbers = new int[max];
  23.  
  24.             timer.Restart();
  25.             Console.SetIn(File.OpenText(@"../../input.txt"));
  26.             string[] splits = Console.ReadLine().Split(' ');
  27.             for (int i = 0; i < max; i++)
  28.             {
  29.                 numbers[i] = int.Parse(splits[i]);
  30.             }
  31.             Console.In.Close();
  32.             timer.Stop();
  33.            
  34.             Console.SetIn(std);
  35.             Console.WriteLine("Time taken to load all values: " + timer.Elapsed.TotalSeconds + "s");
  36.             Console.ReadLine();
  37.            
  38.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement