Attribute-Benchmark
view release on metacpan or search on metacpan
lib/Attribute/Benchmark.pm view on Meta::CPAN
use 5.008;
use strict;
use warnings;
package Attribute::Benchmark;
use Attribute::Handlers ();
use Benchmark ();
our $AUTHORITY = 'cpan:TOBYINK';
our $VERSION = '0.001';
my %cmp = ();
my $iter = -3;
END { Benchmark::cmpthese($iter, \%cmp) if keys %cmp };
sub import
{
shift;
$iter = $_[0] if @_;
strict->import;
warnings->import(FATAL => 'all');
}
sub UNIVERSAL::Benchmark :ATTR()
{
(my $name = $_[4] ? $_[4][0] : substr(*{$_[1]}, 1))
=~ s/\Amain:://;
$cmp{$name} = $_[2];
}
1;
__END__
=pod
=encoding utf-8
=for stopwords peasy squeezy benchmarking
=head1 NAME
Attribute::Benchmark - dead easy benchmarking
=head1 SYNOPSIS
#!/usr/bin/env perl
use Attribute::Benchmark;
sub foo :Benchmark
{
1 for 0..10;
}
sub bar1 :Benchmark(bar)
{
1 for 0..1000;
}
That's all folks!
=head1 DESCRIPTION
B<Attribute::Benchmark> provides a C<:Benchmark> attribute for subs.
Just import it into a script, write the subs you wish to compare, and
add the C<:Benchmark> attribute to each. Then run your script.
No need to C<use strict> or C<use warnings> - Attribute::Benchmark
does that for you.
By default Attribute::Benchmark uses C<< cmpthese(-3, \%subs) >> but
the iteration count can be changed in the import statement:
use Attribute::Benchmark (100);
Don't forget the parentheses; otherwise Perl will assume you want
version 100.0 of Attribute::Benchmark!
Attribute::Benchmark will use the name of the sub as the label for the
( run in 0.563 second using v1.01-cache-2.11-cpan-e93a5daba3e )