fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Diagnostics;
  5.  
  6. namespace CSharpTest
  7. {
  8. class MainClass
  9. {
  10. private static void TestListCount(int n)
  11. {
  12. for (int i = 1; i <= n; i *= 2)
  13. {
  14. var l = new List<int>(Enumerable.Range(0, i));
  15. var scaledBy2 = l.Select (x => x * 2);
  16. int actualCount = 0;
  17.  
  18. var sw = new Stopwatch();
  19. sw.Reset();
  20. sw.Start();
  21.  
  22. actualCount = scaledBy2.Count();
  23.  
  24. sw.Stop();
  25.  
  26. Console.WriteLine("{0} for N = {1} -> {2}, List<int>.Select(..).Count()", sw.Elapsed, i, actualCount);
  27. }
  28. }
  29.  
  30. private static void TestArrayCount(int n)
  31. {
  32. for (int i = 1; i <= n; i *= 2)
  33. {
  34. var arr = Enumerable.Range(0, i).ToArray();
  35. var scaledBy2 = arr.Select (x => x * 2);
  36. int actualCount = 0;
  37.  
  38. var sw = new Stopwatch();
  39. sw.Reset();
  40. sw.Start();
  41.  
  42. actualCount = scaledBy2.Count();
  43.  
  44. sw.Stop();
  45.  
  46. Console.WriteLine("{0} for N = {1} -> {2}, Array<int>.Select(..).Count()", sw.Elapsed, i, actualCount);
  47. }
  48. }
  49.  
  50. public static void Main (string[] args)
  51. {
  52. const int n = 16777216;
  53.  
  54. TestListCount(n);
  55. TestArrayCount(n);
  56. }
  57. }
  58. }
  59.  
Time limit exceeded #stdin #stdout 5s 210880KB
stdin
Standard input is empty
stdout
00:00:00.0016397 for N = 1 -> 1, List<int>.Select(..).Count()
00:00:00.0000025 for N = 2 -> 2, List<int>.Select(..).Count()
00:00:00.0000013 for N = 4 -> 4, List<int>.Select(..).Count()
00:00:00.0000024 for N = 8 -> 8, List<int>.Select(..).Count()
00:00:00.0000019 for N = 16 -> 16, List<int>.Select(..).Count()
00:00:00.0000027 for N = 32 -> 32, List<int>.Select(..).Count()
00:00:00.0000047 for N = 64 -> 64, List<int>.Select(..).Count()
00:00:00.0000086 for N = 128 -> 128, List<int>.Select(..).Count()
00:00:00.0000162 for N = 256 -> 256, List<int>.Select(..).Count()
00:00:00.0000452 for N = 512 -> 512, List<int>.Select(..).Count()
00:00:00.0000681 for N = 1024 -> 1024, List<int>.Select(..).Count()
00:00:00.0001309 for N = 2048 -> 2048, List<int>.Select(..).Count()
00:00:00.0002516 for N = 4096 -> 4096, List<int>.Select(..).Count()
00:00:00.0004989 for N = 8192 -> 8192, List<int>.Select(..).Count()
00:00:00.0010087 for N = 16384 -> 16384, List<int>.Select(..).Count()
00:00:00.0018914 for N = 32768 -> 32768, List<int>.Select(..).Count()
00:00:00.0036983 for N = 65536 -> 65536, List<int>.Select(..).Count()
00:00:00.0073336 for N = 131072 -> 131072, List<int>.Select(..).Count()
00:00:00.0158878 for N = 262144 -> 262144, List<int>.Select(..).Count()
00:00:00.0331623 for N = 524288 -> 524288, List<int>.Select(..).Count()
00:00:00.0588593 for N = 1048576 -> 1048576, List<int>.Select(..).Count()
00:00:00.1186558 for N = 2097152 -> 2097152, List<int>.Select(..).Count()
00:00:00.2410345 for N = 4194304 -> 4194304, List<int>.Select(..).Count()
00:00:00.4747572 for N = 8388608 -> 8388608, List<int>.Select(..).Count()
00:00:00.9416511 for N = 16777216 -> 16777216, List<int>.Select(..).Count()
00:00:00.0009783 for N = 1 -> 1, Array<int>.Select(..).Count()
00:00:00.0000013 for N = 2 -> 2, Array<int>.Select(..).Count()
00:00:00.0000010 for N = 4 -> 4, Array<int>.Select(..).Count()
00:00:00.0000013 for N = 8 -> 8, Array<int>.Select(..).Count()
00:00:00.0000017 for N = 16 -> 16, Array<int>.Select(..).Count()
00:00:00.0000033 for N = 32 -> 32, Array<int>.Select(..).Count()
00:00:00.0000047 for N = 64 -> 64, Array<int>.Select(..).Count()
00:00:00.0000085 for N = 128 -> 128, Array<int>.Select(..).Count()
00:00:00.0000199 for N = 256 -> 256, Array<int>.Select(..).Count()
00:00:00.0000394 for N = 512 -> 512, Array<int>.Select(..).Count()
00:00:00.0000788 for N = 1024 -> 1024, Array<int>.Select(..).Count()
00:00:00.0001291 for N = 2048 -> 2048, Array<int>.Select(..).Count()
00:00:00.0002796 for N = 4096 -> 4096, Array<int>.Select(..).Count()
00:00:00.0005858 for N = 8192 -> 8192, Array<int>.Select(..).Count()
00:00:00.0011117 for N = 16384 -> 16384, Array<int>.Select(..).Count()
00:00:00.0021328 for N = 32768 -> 32768, Array<int>.Select(..).Count()
00:00:00.0043364 for N = 65536 -> 65536, Array<int>.Select(..).Count()
00:00:00.0085871 for N = 131072 -> 131072, Array<int>.Select(..).Count()
00:00:00.0163359 for N = 262144 -> 262144, Array<int>.Select(..).Count()
00:00:00.0384374 for N = 524288 -> 524288, Array<int>.Select(..).Count()
00:00:00.0654653 for N = 1048576 -> 1048576, Array<int>.Select(..).Count()
00:00:00.1386116 for N = 2097152 -> 2097152, Array<int>.Select(..).Count()
00:00:00.2617989 for N = 4194304 -> 4194304, Array<int>.Select(..).Count()
00:00:00.5194144 for N = 8388608 -> 8388608, Array<int>.Select(..).Count()