#!/usr/bin/env perl
use strict;
use warnings;
use Perl::Critic;
use Benchmark ':hireswallclock';
#---------------------------------------------------------------
our $VERSION = '1.119';
#---------------------------------------------------------------
my @exclude = qw(TidyCode PodSpelling); # We can't really optimize these
my %pc_opts = (-profile => '', -theme => 'core', -severity => 1, -exclude => \@exclude);
my $pc = Perl::Critic->new( %pc_opts );
my $test_file = shift @ARGV || die "Must specify a test file.\n";
my $iters = shift @ARGV || 10;
my $code_ref = sub { $pc->critique($test_file) for 1 .. $iters };
my $t = timeit( 1, $code_ref, "Critqiue of $test_file");
print "$iters iterations took: ",timestr($t),"\n";
exit;
#---------------------------------------------------------------
__END__
=pod
=head1 NAME
pc-benchmark - Measure performance of Perl::Critic
=head1 SYNOPSIS
pc-benchmark FILE
PERL5LIB=foo/bar/lib pc-benchmark FILE
perl -Ifoo/bar/lib pc-benchmark FILE
=head1 DESCRIPTION
This is a simple program that uses the L<Benchmark> module to measure
the general speed of L<Perl::Critic>. For the specified F<FILE>, the
C<Perl::Critic::critique()> function is called 100 times, with all the
'core' Policies enabled with their default configuration. The total
elapsed/system/user/ time is displayed.
To compare the performance of two versions of L<Perl::Critic>, you'll
need to run this command twice, and alter the C<@INC> so that it loads
the right version of the libraries you want to use. For example:
PERL5LIB=/path/to/slow/version/lib pc-benchmark FILE
PERL5LIB=/path/to/fast/version/lib pc-benchmark FILE
For an apples-to-apples comparison, be sure to use the same F<FILE>
for both runs.
=head1 CAVEATS
This is the first time I've used L<Benchmark>, so I don't know if this
program is "correct" or even useful. It just seemed like an interesting
thing to do.
=head1 AUTHOR
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
=head1 COPYRIGHT
Copyright (c) 2009-2011 Imaginative Software Systems. All rights reserved.
=cut