Advertisement
tbrowder

run-rw-tests.p6

Feb 3rd, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.36 KB | None | 0 0
  1. #!/usr/bin/env perl6
  2.  
  3. # test file sizes:
  4. #my @GB = <0 1 2 3 4 5 6 7 8 9 10>;
  5. my @GB = <0>; # a small file for testing this file
  6.  
  7. my $run-perl6 = True;
  8. #my $run-perl6 = False; # for speedy testing of this file
  9.  
  10. # get perl versions
  11.  
  12. # perl 5 =====
  13. # one-liner to get perl 5 version:
  14. # $ perl -e 'printf "%vd\n", $^V'
  15. # 5.14.2
  16. my $proc = shell "perl -e 'printf \"\%vd\", \$^V'", :out;
  17. my $p5v = $proc.out.slurp-rest;
  18. #die "DEBUG: Perl 5 version: $p5v";
  19.  
  20. # perl 6 =====
  21. $proc = shell "perl6 -v", :out;
  22. my $p6v = $proc.out.slurp-rest;
  23. #die "DEBUG: Perl 6 version: $p6v";
  24.  
  25. # put all output in a log file
  26. my $stamp = my-date-time-stamp;
  27. my $ofil = 'run-rw-tests-' ~ $stamp ~ '.log';
  28. my $fp = open($ofil, :w);
  29.  
  30. my $sdate = my-date-time;
  31. my $start = now;
  32. $fp.say("====================================");
  33. $fp.say("# Start testing at: $sdate");
  34. $fp.say("# Perl 5 version: $p5v");
  35. my @s = $p6v.lines;
  36. my $s = @s.join(' ');
  37. @s = $s.words;
  38. ## 'This is Rakudo version 2015.12 built on MoarVM version 2015.12 implementing Perl 6.c.'
  39. my ($rv, $mv, $pv) = (@s[4], @s[9], @s[*-1]);
  40. $pv ~~ s/\.$//;
  41. #say "# Perl 6 version: $p6v";
  42. #say "# Perl 6 version: $s";
  43. $fp.say("# Perl 6 version: $pv");
  44. $fp.say("# Rakudo version: $rv");
  45. $fp.say("# MoarVM version: $mv");
  46. $fp.say("====================================");
  47.  
  48. my $P5R = './read-file-test.pl';
  49. my $P5W = './create-large-file.pl';
  50. my $P6R = './read-file-test.p6';
  51. my $P6W = './create-large-file.p6';
  52.  
  53. my $ntests = 0;
  54. for @GB -> $G {
  55. my $sdate = my-date-time;
  56. $fp.say("#***** Working with $G Gb...");
  57. $fp.say("# Starting at: $sdate");
  58. my $LFIL = 'large-' ~ $G ~ '-gb-file.txt';
  59. if !$LFIL.IO.f {
  60. # choose which Perl to create the missing files
  61. #my $wver = 5;
  62. my $wver = 6;
  63. my $wexe = $wver == 5 ?? $P5W !! $P6W;
  64. $fp.say(" #---------------------------------");
  65. $fp.say(" # Creating file '$LFIL' with Perl $wver...");
  66. $fp.say(" #---------------------------------");
  67. my $proc = shell "$wexe $G", :out;
  68. my $s = $proc.out.slurp-rest;
  69. $s.=chomp;
  70. #my @s = $s.words;
  71. for $s.lines -> $line {
  72. $fp.say(" $line");
  73. }
  74. }
  75.  
  76. my ($proc, $s);
  77. {
  78. $fp.say(" #---------------------------------");
  79. $fp.say(" # Start read process...");
  80. $fp.say(" #---------------------------------");
  81. my $pstart = now;
  82. $fp.say(" Reading file '$LFIL' with Perl 5...");
  83. $proc = shell "$P5R $LFIL", :out;
  84. $s = $proc.out.slurp-rest;
  85. $s.=chomp;
  86. $fp.say($s);
  87. ++$ntests;
  88.  
  89. # show some time stats
  90. my $pend = now;
  91. my $pet = $pend - $pstart;
  92. my $pets = sprintf "%.2f", $pet;
  93. my $ps = $pet < 1000 ?? " ($pets s)" !! '';
  94. my $pdt = delta-time($pet);
  95. $pdt.=Str;
  96. $fp.say(" #---------------------------------");
  97. $fp.say(" # End read process - delta time: $pdt$ps");
  98. $fp.say(" #---------------------------------");
  99. $fp.flush;
  100. }
  101.  
  102. if $run-perl6 {
  103. $fp.say(" #---------------------------------");
  104. $fp.say(" # Start read process...");
  105. $fp.say(" #---------------------------------");
  106. my $pstart = now;
  107. $fp.say(" Reading file '$LFIL' with Perl 6...");
  108. $proc = shell "$P6R $LFIL", :out;
  109. $s = $proc.out.slurp-rest;
  110. $s.=chomp;
  111. $fp.say($s);
  112. ++$ntests;
  113.  
  114. # show some time stats
  115. my $pend = now;
  116. my $pet = $pend - $pstart;
  117. my $pets = sprintf "%.2f", $pet;
  118. my $ps = $pet < 1000 ?? " ($pets s)" !! '';
  119. my $pdt = delta-time($pet);
  120. $pdt.=Str;
  121. $fp.say(" #---------------------------------");
  122. $fp.say(" # End read process - delta time: $pdt$ps");
  123. $fp.say(" #---------------------------------");
  124. $fp.flush;
  125. }
  126.  
  127. # check that char and line counts are correct
  128. $fp.say(" Reading file '$LFIL' with system wc...");
  129. $proc = shell "wc $LFIL", :out;
  130. my $wc = $proc.out.slurp-rest;
  131. $wc.=chomp;
  132. $fp.say(" $wc");
  133. $fp.say("#***** End working with $G Gb");
  134. $fp.flush;
  135. }
  136. $fp.say("====================================");
  137. $fp.say("End testing.");
  138. $fp.say("====================================");
  139.  
  140. my $end = now;
  141. my $et = $end - $start;
  142. my $edate = my-date-time;
  143. $s = $ntests > 1 ?? 's' !! '';
  144.  
  145. $fp.say("====================================");
  146. $fp.say("$ntests test$s completed.");
  147. $fp.say("WARNING: No Perl 6 tests were run.") if !$run-perl6;
  148. $fp.say("End time: $edate");
  149. $fp.say("Total elapsed time: $et sec");
  150. my $dt = delta-time($et);
  151. $dt.=Str;
  152. $fp.say("Delta time: $dt");
  153. $fp.say("====================================");
  154.  
  155. say "Normal end.";
  156. say "$ntests test$s completed.";
  157. say "WARNING: No Perl 6 tests were run." if !$run-perl6;
  158. say "End time: $edate";
  159. say "Total elapsed time: $et sec";
  160. say "See log file '$ofil'.";
  161.  
  162. #### subroutines ####
  163. sub my-date-time {
  164. my $date = DateTime.now(formatter => {
  165. sprintf "%04d-%02d-%02d %02d:%02d:%05.2f",
  166. .year, .month, .day, .hour, .minute, .second});
  167. return $date;
  168. }
  169.  
  170. sub my-date-time-stamp {
  171. my $date = DateTime.now(formatter => {
  172. # bzr-friendly format (no ':' used)
  173. sprintf "%04d-%02d-%02dT%02dh%02dm%05.2fs",
  174. .year, .month, .day, .hour, .minute, .second});
  175. return $date;
  176. }
  177.  
  178. sub delta-time($Time) {
  179. my Num $time = $Time.Num;
  180.  
  181. my Int $sec-per-min = 60;
  182. my Int $min-per-hr = 60;
  183. my Int $sec-per-hr = $sec-per-min * $min-per-hr;
  184.  
  185. my Int $hr = ($time/$sec-per-hr).Int;
  186. my Num $sec = $time - ($sec-per-hr * $hr);
  187. my Int $min = ($sec/$sec-per-min).Int;
  188. $sec = $sec - ($sec-per-min * $min);
  189. return sprintf "%dh%02dm%05.2fs", $hr, $min, $sec;
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement