fork download
  1.  
  2. import std.stdio;
  3. import std.perf;
  4.  
  5. /++
  6. + - 配列のスライシング
  7. + forによる繰り返しより、かなり高速
  8. +/
  9.  
  10. void main()
  11. {
  12. // erapsed time = 0(secs)/ 26(millis)/25578(micros)
  13. // erapsed time = 0(secs)/ 7(millis)/7519(micros)
  14.  
  15. uint[81] s =
  16. [
  17. 1, 2, 3, 4, 5, 6, 7, 8, 9,
  18. 2, 4, 6, 8,10,12,14,16,18,
  19. 3, 6, 9,12,15,18,21,24,27,
  20. 4, 8,12,16,20,24,28,32,36,
  21. 5,10,15,20,25,30,35,40,45,
  22. 6,12,18,24,30,36,42,48,54,
  23. 7,14,21,28,35,42,49,56,63,
  24. 8,16,24,32,40,48,56,64,72,
  25. 9,18,27,36,45,54,63,72,81,
  26. ];
  27. uint[81] d;
  28.  
  29. auto sw = new PerformanceCounter;
  30.  
  31. // 測定スタート
  32. sw.start();
  33. for (int i; i < 100000; i++)
  34. {
  35. // do something
  36. for (int j; j < 81; j++)
  37. d[j] = s[j];
  38. }
  39. // 測定ストップ
  40. sw.stop();
  41. writefln("erapsed time = %d(secs)/ %d(millis)/%d(micros)",
  42. sw.seconds(), sw.milliseconds(), sw.microseconds());
  43.  
  44. // 測定スタート
  45. sw.start();
  46. for (int i; i < 100000; i++)
  47. {
  48. // do something
  49. d[0 .. s.length] = s[0 .. $];
  50. }
  51. // 測定ストップ
  52. sw.stop();
  53. writefln("erapsed time = %d(secs)/ %d(millis)/%d(micros)",
  54. sw.seconds(), sw.milliseconds(), sw.microseconds());
  55. }
  56.  
Success #stdin #stdout 0.05s 2120KB
stdin
Standard input is empty
stdout
erapsed time = 0(secs)/ 26(millis)/25584(micros)
erapsed time = 0(secs)/ 7(millis)/7516(micros)