Change 17774 by [EMAIL PROTECTED] on 2002/08/25 15:29:42

        Subject: [PATCH lib/Benchmark.(pm|t)]  Make cmpthese work as documented.
        From: Abigail <[EMAIL PROTECTED]>
        Date: Thu, 22 Aug 2002 04:10:39 -0700
        Message-ID: <[EMAIL PROTECTED]>

Affected files ...

.... //depot/perl/lib/Benchmark.pm#30 edit
.... //depot/perl/lib/Benchmark.t#11 edit

Differences ...

==== //depot/perl/lib/Benchmark.pm#30 (text) ====
Index: perl/lib/Benchmark.pm
--- perl/lib/Benchmark.pm#29~16693~     Sun May 19 07:28:37 2002
+++ perl/lib/Benchmark.pm       Sun Aug 25 08:29:42 2002
@@ -196,7 +196,7 @@
 
 Clear all cached times.
 
-=item cmpthese ( COUT, CODEHASHREF, [ STYLE ] )
+=item cmpthese ( COUNT, CODEHASHREF, [ STYLE ] )
 
 =item cmpthese ( RESULTSHASHREF, [ STYLE ] )
 
@@ -412,7 +412,7 @@
              clearcache clearallcache disablecache enablecache);
 %EXPORT_TAGS=( all => [ @EXPORT, @EXPORT_OK ] ) ;
 
-$VERSION = 1.04;
+$VERSION = 1.05;
 
 &init;
 
@@ -713,7 +713,9 @@
 }
 
 sub cmpthese{
-    my ($results, $style) = ref $_[0] ? @_ : ( timethese( @_[0,1,2] ), $_[2] ) ;
+    my ($results, $style) =
+         ref $_ [0] ? @_
+                    : (timethese (@_ [0, 1], @_ > 2 ? $_ [2] : "none"), $_ [2]);
 
     $style = "" unless defined $style;
 

==== //depot/perl/lib/Benchmark.t#11 (text) ====
Index: perl/lib/Benchmark.t
--- perl/lib/Benchmark.t#10~16583~      Mon May 13 16:04:00 2002
+++ perl/lib/Benchmark.t        Sun Aug 25 08:29:42 2002
@@ -8,7 +8,7 @@
 use warnings;
 use strict;
 use vars qw($foo $bar $baz $ballast);
-use Test::More tests => 159;
+use Test::More tests => 173;
 
 use Benchmark qw(:all);
 
@@ -346,7 +346,7 @@
 {
     select(OUT);
     my $start = times;
-    my $chart = cmpthese( -0.1, { a => "++\$i", b => "\$i = sqrt(\$i++)" } ) ;
+    my $chart = cmpthese( -0.1, { a => "++\$i", b => "\$i = sqrt(\$i++)" }, "auto" ) ;
     my $end = times;
     select(STDOUT);
     ok (($end - $start) > 0.05, "benchmarked code ran for over 0.05 seconds");
@@ -360,6 +360,28 @@
     # Remove the title
     $got =~ s/.*\.\.\.//s;
     like ($got, $default_pattern, 'should find default format somewhere');
+    like ($got, $graph_dissassembly, "Should find the output graph somewhere");
+    check_graph_vs_output ($chart, $got);
+}
+
+# Not giving auto should suppress timethese results.
+{
+    select(OUT);
+    my $start = times;
+    my $chart = cmpthese( -0.1, { a => "++\$i", b => "\$i = sqrt(\$i++)" } ) ;
+    my $end = times;
+    select(STDOUT);
+    ok (($end - $start) > 0.05, "benchmarked code ran for over 0.05 seconds");
+
+    $got = $out->read();
+    # Remove any warnings about having too few iterations.
+    $got =~ s/\(warning:[^\)]+\)//gs;
+
+    unlike ($got, qr/running\W+a\W+b.*?for at least 0\.1 CPU second/s,
+          'should not have title');
+    # Remove the title
+    $got =~ s/.*\.\.\.//s;
+    unlike ($got, $default_pattern, 'should not find default format somewhere');
     like ($got, $graph_dissassembly, "Should find the output graph somewhere");
     check_graph_vs_output ($chart, $got);
 }
End of Patch.

Reply via email to