fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Text;
  6.  
  7.  
  8. namespace ConsoleApplication1
  9. {
  10. /// <summary>
  11. /// My unbelievably awesome, non-generic, Program-class.
  12. /// ---------
  13. /// Notes:
  14. /// ctrl + m, ctrl + (l,o) : Collapse, expand code
  15. /// </summary>
  16. class Program
  17. {
  18. /// <summary>
  19. /// This method defines the entry point of each csharp program. Kinda funny, eh? :)
  20. /// </summary>
  21. /// <param name="args">The console args.</param>
  22. static void Main(string[] args)
  23. {
  24. const int NUM_ITEMS = 1000000;
  25.  
  26. List<int> list = new List<int>(NUM_ITEMS);
  27. Stopwatch stopwatch = new Stopwatch();
  28.  
  29. {
  30. // Insert
  31. stopwatch.Start();
  32. for (int i = 0; i < NUM_ITEMS; ++i)
  33. {
  34. list.Add(i);
  35. }
  36. stopwatch.Stop();
  37.  
  38. Console.WriteLine("Insert dt:" + stopwatch.ElapsedMilliseconds);
  39. }
  40. stopwatch.Reset();
  41. {
  42. // Read
  43. long sum = 0;
  44. stopwatch.Start();
  45. for (int i = 0; i < NUM_ITEMS; ++i)
  46. {
  47. sum += list[i];
  48. }
  49. stopwatch.Stop();
  50.  
  51. Console.WriteLine("Read dt:" + stopwatch.ElapsedMilliseconds);
  52. Console.WriteLine("Read sum: " + sum);
  53. }
  54.  
  55. }
  56.  
  57. }
  58. }
  59.  
Success #stdin #stdout 0.06s 40984KB
stdin
Standard input is empty
stdout
Insert dt:10
Read dt:8
Read sum: 499999500000