summaryrefslogtreecommitdiff
path: root/lib/Benchmark.t
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2015-11-28 16:44:12 +0000
committerDavid Mitchell <davem@iabyn.com>2015-11-28 16:47:17 +0000
commit534c402b078fa982333009833073f52917b61b71 (patch)
treed9013551e5ea3720d389e1af7f2ff3c87c892ac0 /lib/Benchmark.t
parent8dddc15610773a292e6fe8f989e51dd8c27ac1de (diff)
downloadperl-534c402b078fa982333009833073f52917b61b71.tar.gz
Benchmark.t: better diagnostics
use cmp_ok() instesd of ok() where apppriate and similar things to get better diagnostucs when things fail (e.g. display what the bad value was, rather than just letting you know it was bad). Also, use diag() rather than 'print STDERR "# .....\n";'
Diffstat (limited to 'lib/Benchmark.t')
-rw-r--r--lib/Benchmark.t44
1 files changed, 22 insertions, 22 deletions
diff --git a/lib/Benchmark.t b/lib/Benchmark.t
index 080641d7f9..4bf01b222e 100644
--- a/lib/Benchmark.t
+++ b/lib/Benchmark.t
@@ -69,7 +69,7 @@ isa_ok($threesecs, 'Benchmark', "countit 0, CODEREF");
isnt ($baz, 0, "benchmarked code was run");
my $in_threesecs = $threesecs->iters;
print "# in_threesecs=$in_threesecs iterations\n";
-ok ($in_threesecs > 0, "iters returned positive iterations");
+cmp_ok($in_threesecs, '>', 0, "iters returned positive iterations");
my $cpu3 = $threesecs->[1]; # user
my $sys3 = $threesecs->[2]; # sys
cmp_ok($cpu3+$sys3, '>=', 3.0, "3s cpu3 is at least 3s");
@@ -85,7 +85,7 @@ isa_ok($onesec, 'Benchmark', "countit 1, CODEREF");
isnt ($baz, 0, "benchmarked code was run");
my $in_onesec = $onesec->iters;
print "# in_onesec=$in_onesec iterations\n";
-ok ($in_onesec > 0, "iters returned positive iterations");
+cmp_ok($in_onesec, '>', 0, "iters returned positive iterations");
my $cpu1 = $onesec->[1]; # user
my $sys1 = $onesec->[2]; # sys
cmp_ok($cpu1+$sys1, '>=', 1.0, "is cpu1 is at least 1s");
@@ -102,7 +102,7 @@ isa_ok($onesec, 'Benchmark', "countit 1, eval");
isnt ($baz, 0, "benchmarked code was run");
my $in_again = $again->iters;
print "# $in_again iterations\n";
-ok ($in_again > 0, "iters returned positive iterations");
+cmp_ok($in_again, '>', 0, "iters returned positive iterations");
my $t1 = new Benchmark;
@@ -201,8 +201,8 @@ like ($got, $Nop_Pattern, 'specify format as nop');
select(STDOUT);
isa_ok($got, 'Benchmark',
"timethis, at least 2 seconds with format 'none'");
- ok ($foo > 0, "benchmarked code was run");
- ok ($end - $start > 1, "benchmarked code ran for over 1 second");
+ cmp_ok($foo, '>', 0, "benchmarked code was run");
+ cmp_ok($end - $start, '>', 1, "benchmarked code ran for over 1 second");
$got = $out->read();
# Remove any warnings about having too few iterations.
@@ -288,10 +288,10 @@ my $results;
isa_ok($results->{Foo}, 'Benchmark', "Foo value");
isa_ok($results->{Bar}, 'Benchmark', "Bar value");
eq_set([keys %$results], [qw(Foo Bar)], 'should be exactly two objects');
- ok ($foo > 0, "Foo code was run");
- ok ($bar > 0, "Bar code was run");
+ cmp_ok($foo, '>', 0, "Foo code was run");
+ cmp_ok($bar, '>', 0, "Bar code was run");
- ok (($end - $start) > 0.1, "benchmarked code ran for over 0.1 seconds");
+ cmp_ok($end-$start, '>', 0.1, "benchmarked code ran for over 0.1 seconds");
$got = $out->read();
# Remove any warnings about having too few iterations.
@@ -347,11 +347,10 @@ sub check_graph_consistency {
pass ("slow rate is less than fast rate");
unless (ok ($slowfast <= 0 && $slowfast >= -100,
"slowfast should be less than or equal to zero, and >= -100")) {
- print STDERR "# slowfast $slowfast\n";
+ diag("slowfast=$slowfast");
$all_passed = 0;
}
- unless (ok ($fastslow > 0, "fastslow should be > 0")) {
- print STDERR "# fastslow $fastslow\n";
+ unless (cmp_ok($fastslow, '>', 0, "fastslow should be > 0")) {
$all_passed = 0;
}
} else {
@@ -384,8 +383,7 @@ sub check_graph_vs_output {
[$fastr, $fastratet, $fastslowt, $fastfast]],
"check the chart layout matches the formatted output");
unless ($all_passed) {
- print STDERR "# Something went wrong there. I got this chart:\n";
- print STDERR "# $_\n" foreach split /\n/, $got;
+ diag("Something went wrong there. I got this chart:\n$got");
}
}
@@ -406,7 +404,8 @@ sub check_graph {
}, "auto" ) ;
my $end = times;
select(STDOUT);
- ok (($end - $start) > 0.05, "benchmarked code ran for over 0.05 seconds");
+ cmp_ok($end - $start, '>', 0.05,
+ "benchmarked code ran for over 0.05 seconds");
$got = $out->read();
# Remove any warnings about having too few iterations.
@@ -429,7 +428,8 @@ sub check_graph {
b => "\$i = sqrt(\$i++)" });
my $end = times;
select(STDOUT);
- ok (($end - $start) > 0.05, "benchmarked code ran for over 0.05 seconds");
+ cmp_ok($end - $start, '>', 0.05,
+ "benchmarked code ran for over 0.05 seconds");
$got = $out->read();
# Remove any warnings about having too few iterations.
@@ -449,8 +449,8 @@ sub check_graph {
select(OUT);
my $chart = cmpthese($iterations, $code_to_test, 'nop' ) ;
select(STDOUT);
- ok ($foo > 0, "Foo code was run");
- ok ($bar > 0, "Bar code was run");
+ cmp_ok($foo, '>', 0, "Foo code was run");
+ cmp_ok($bar, '>', 0, "Bar code was run");
$got = $out->read();
# Remove any warnings about having too few iterations.
@@ -469,8 +469,8 @@ sub check_graph {
select(OUT);
my $chart = cmpthese($iterations, $code_to_test, 'none' ) ;
select(STDOUT);
- ok ($foo > 0, "Foo code was run");
- ok ($bar > 0, "Bar code was run");
+ cmp_ok($foo, '>', 0, "Foo code was run");
+ cmp_ok($bar, '>', 0, "Bar code was run");
$got = $out->read();
# Remove any warnings about having too few iterations.
@@ -493,8 +493,8 @@ sub check_graph {
my $res = timethese($iterations, $code_to_test, 'none' ) ;
my $chart = cmpthese($res, 'none' ) ;
select(STDOUT);
- ok ($foo > 0, "Foo code was run");
- ok ($bar > 0, "Bar code was run");
+ cmp_ok($foo, '>', 0, "Foo code was run");
+ cmp_ok($bar, '>', 0, "Bar code was run");
$got = $out->read();
# Remove any warnings about having too few iterations.
@@ -519,7 +519,7 @@ sub check_graph {
is ($bar, 0, "Bar code was not run");
$got = $out->read();
- ok ($got !~ /\.\.\./s, 'check that there is no title');
+ unlike($got, qr/\.\.\./s, 'check that there is no title');
like ($got, $graph_dissassembly, "Should find the output graph somewhere");
check_graph_vs_output ($chart, $got);
}