4 use Time::HiRes 'time';
6 use IPC::System::Simple 'system';
8 use Parse::BACKPAN::Packages;
11 use File::Slurp 'slurp';
13 my $backpan = Parse::BACKPAN::Packages->new;
14 my @cmops = $backpan->distributions('Class-MOP');
15 my @mooses = $backpan->distributions('Moose');
20 my $base = "http://backpan.cpan.org/";
25 open my $output, ">", "moose_bench.txt";
27 for my $moose (@mooses) {
28 my $moose_dir = build($moose);
30 # Find the CMOP dependency
31 my $makefile = slurp("$moose_dir/Makefile.PL");
32 my ($cmop_dep) = $makefile =~ /Class::MOP.*?([0-9._]+)/
33 or die "Unable to find Class::MOP version dependency in $moose_dir/Makefile.PL";
36 $cmop_dep = '0.64_07' if $cmop_dep eq '0.6407';
38 # nonexistent dev releases?
39 $cmop_dep = '0.79' if $cmop_dep eq '0.78_02';
40 $cmop_dep = '0.83' if $cmop_dep eq '0.82_01';
42 bump_cmop($cmop_dep, $moose);
44 warn "Building $moose_dir";
46 system("(cd '$moose_dir' && '$^X' '-I$cmop_dir/lib' Makefile.PL && make && sudo make install) >/dev/null");
55 '-e', 'package Class; use Moose;',
57 push @times, time - $start;
60 $time{$moose->version} = sum(@times) / @times;
61 $mem{$moose->version} = qx[$^X -I$moose_dir/lib -I$cmop_dir/lib -MGTop -e 'my (\$gtop, \$before); BEGIN { \$gtop = GTop->new; \$before = \$gtop->proc_mem(\$\$)->size; } package Class; use Moose; print \$gtop->proc_mem(\$\$)->size - \$before'];
62 my $line = sprintf "%7s: %0.4f (%s), %d bytes\n",
64 $time{$moose->version},
65 join(', ', map { sprintf "%0.4f", $_ } @times),
66 $mem{$moose->version};
72 require Chart::Clicker;
73 require Chart::Clicker::Data::Series;
74 require Chart::Clicker::Data::DataSet;
75 my @versions = sort keys %time;
76 my @startups = map { $time{$_} } @versions;
77 my @memories = map { int($mem{$_} / 1024) } @versions;
78 my @keys = (0..$#versions);
79 my $cc = Chart::Clicker->new(width => 900, height => 400);
80 my $sutime = Chart::Clicker::Data::Series->new(
83 name => 'Startup Time',
85 my $def = $cc->get_context('default');
86 $def->domain_axis->tick_values(\@keys);
87 $def->domain_axis->tick_labels(\@versions);
88 $def->domain_axis->tick_label_angle(1.57);
89 $def->domain_axis->tick_font->size(8);
90 $def->range_axis->fudge_amount('0.05');
92 my $context = Chart::Clicker::Context->new(name => 'memory');
93 $context->range_axis->tick_values([qw(1024 2048 3072 4096 5120)]);
94 $context->range_axis->format('%d');
95 $context->domain_axis->hidden(1);
96 $context->range_axis->fudge_amount('0.05');
97 $cc->add_to_contexts($context);
99 my $musage = Chart::Clicker::Data::Series->new(
100 values => \@memories,
102 name => 'Memory Usage (kb)'
105 my $ds1 = Chart::Clicker::Data::DataSet->new(series => [ $sutime ]);
106 my $ds2 = Chart::Clicker::Data::DataSet->new(series => [ $musage ]);
107 $ds2->context('memory');
109 $cc->add_to_datasets($ds1);
110 $cc->add_to_datasets($ds2);
111 $cc->write_output('moose_bench.png');
114 my $expected = shift;
117 return $cmop_dir if $cmop_version eq $expected;
119 my @orig_cmops = @cmops;
120 shift @cmops until !@cmops || $cmops[0]->version eq $expected;
122 die "Ran out of cmops, wanted $expected for "
124 . " (had " . join(', ', map { $_->version } @orig_cmops) . ")"
127 $cmop_version = $cmops[0]->version;
128 $cmop_dir = build($cmops[0]);
130 warn "Building $cmop_dir";
131 system("(cd '$cmop_dir' && '$^X' Makefile.PL && make && sudo make install) >/dev/null");
138 my $distvname = $dist->distvname;
139 return $distvname if -d $distvname;
141 warn "Downloading $distvname";
142 my $tarball = get($base . $dist->prefix);
143 open my $handle, '<', \$tarball;
145 my $tar = Archive::Tar->new;
149 my ($arbitrary_file) = $tar->list_files;
150 (my $directory = $arbitrary_file) =~ s{/.*}{};