Permalink
Browse files

conditionally use Devel::Size if available

Devel::Size does not work on all
old Perl versions. Although it would
be extremely interesting what values it
reports for the benchmarked data but
it is not worth to fail on that.
  • Loading branch information...
1 parent 89a20ac commit 3216685458deaabb7c8fb5ddf724f4e6ea71d5f9 @renormalist committed May 24, 2012
@@ -3,7 +3,7 @@ package Benchmark::Perl::Formance::Plugin::DPath;
use strict;
use warnings;
-our $VERSION = "0.001";
+our $VERSION = "0.002";
#############################################################
# #
@@ -15,7 +15,6 @@ our $goal;
our $count;
use Clone 'clone';
-use Devel::Size 'total_size';
use Benchmark ':all', ':hireswallclock';
# example use-case is a medium sized TAP-DOM, which we blow up
@@ -447,7 +446,13 @@ sub run_dpath
my @huge_expected = map { $expected } 1..$multi;
$huge_data->{$_} = clone ( $base_data ) foreach 1..$multi;
- my $data_size = total_size ($huge_data);
+ my $data_size;
+ eval qq{use Devel::Size 'total_size'};
+ if ($@) {
+ $data_size = "error-no-Devel-Size-available";
+ } else {
+ $data_size = total_size ($huge_data);
+ }
print STDERR "# Running benchmark. Can take some time ..." if $options->{verbose} && $options->{verbose} > 2;
my $t;
@@ -3,7 +3,7 @@ package Benchmark::Perl::Formance::Plugin::Incubator;
use strict;
use warnings;
-our $VERSION = "0.001";
+our $VERSION = "0.002";
#############################################################
# #
@@ -12,7 +12,6 @@ our $VERSION = "0.001";
#############################################################
use Benchmark ':hireswallclock';
-use Devel::Size 'total_size';
use Math::MatrixReal;
sub matrix_multiply_fixsize
@@ -27,7 +26,13 @@ sub matrix_multiply_fixsize
my @row; $row[$_] = 1 foreach 0..$minigoal-1;
my @matrix; $matrix[$_] = [ @row ] foreach 0..$minigoal-1;
- my $size = total_size(\@matrix);
+ my $size;
+ eval qq{use Devel::Size 'total_size'};
+ if ($@) {
+ $size = "error-no-Devel-Size-available";
+ } else {
+ $size = total_size(\@matrix);
+ }
my $m = Math::MatrixReal->new_from_rows(\@matrix);
my $result;
@@ -3,7 +3,7 @@ package Benchmark::Perl::Formance::Plugin::Mem;
use strict;
use warnings;
-our $VERSION = "0.002";
+our $VERSION = "0.003";
#############################################################
# #
@@ -15,7 +15,6 @@ our $goal;
our $count;
use Benchmark ':hireswallclock';
-use Devel::Size 'total_size';
my @stuff;
@@ -57,7 +56,13 @@ sub main
$count = $options->{fastmode} ? 5 : 20;
$#stuff = $goal;
- my $size = total_size(\@stuff);
+ my $size;
+ eval qq{use Devel::Size 'total_size'};
+ if ($@) {
+ $size = "error-no-Devel-Size-available";
+ } else {
+ $size = total_size(\@stuff);
+ }
return {
total_size_bytes => $size,
@@ -6,7 +6,7 @@ use 5.008;
use strict;
use warnings;
-our $VERSION = "0.001";
+our $VERSION = "0.002";
#############################################################
# #
@@ -24,13 +24,18 @@ use threads;
use threads::shared;
use Benchmark ':hireswallclock';
-use Devel::Size 'total_size';
use Data::Dumper;
my @result : shared;
$#result = 1_000;
-my $size = total_size(\@result);
+my $size;
+eval qq{use Devel::Size 'total_size'};
+if ($@) {
+ $size = "error-no-Devel-Size-available";
+} else {
+ $size = total_size(\@result);
+}
sub run_thread_storm_shared
{

0 comments on commit 3216685

Please sign in to comment.