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);
-my $delta = 0.3;
+my $delta = 0.4;
# Some timing ballast
sub fib {
print "# $in_onesec iterations\n";
ok ($in_onesec > 0, "iters returned positive iterations");
-my $difference = $in_onesec - $estimate;
-ok (abs ($difference / $in_onesec) < $delta,
- "is $in_onesec within $delta of estimate ($estimate)");
+{
+ my $difference = $in_onesec - $estimate;
+ my $actual = abs ($difference / $in_onesec);
+ ok ($actual < $delta, "is $in_onesec within $delta of estimate ($estimate)");
+ print "# $in_onesec is between " . ($delta / 2) .
+ " and $delta of estimate. Not that safe.\n" if $actual > $delta/2;
+}
# I found that the eval'ed version was 3 times faster than the coderef.
# (now it has a different ballast value)
{
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");
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);
+}
+
{
$foo = $bar = 0;
select(OUT);