Skip to content

Commit

Permalink
lang/perl/App-Benchmark: initial import.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.coderepos.org/share/lang/perl/App-Benchmark/trunk@22597 d0d07461-0603-4401-acd4-de1884942a52
  • Loading branch information
Marcel Gruenauer committed Nov 2, 2008
1 parent 2eaa236 commit 9fb517f
Show file tree
Hide file tree
Showing 12 changed files with 304 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .shipit
@@ -0,0 +1,9 @@
steps = FindVersion, ChangeVersion, CheckChangeLog, Manifest, DistTest, Commit, Tag, MakeDist, MyUploadCPAN, DistClean, Twitter

svn.tagpattern = http://svn.coderepos.org/share/lang/perl/App-Benchmark/tags/App-Benchmark-%v

twitter.config = ~/.twitterrc
twitter.distname = App-Benchmark
twitter.message = shipped %d %v - soon at %u


4 changes: 4 additions & 0 deletions Changes
@@ -0,0 +1,4 @@
Revision history for Perl extension App-Benchmark

0.01 2008-11-02T21:31:53Z (Marcel Gruenauer <marcel@cpan.org>)
- original version
24 changes: 24 additions & 0 deletions MANIFEST
@@ -0,0 +1,24 @@
Changes
inc/Module/AutoInstall.pm
inc/Module/Install.pm
inc/Module/Install/AutoInstall.pm
inc/Module/Install/Base.pm
inc/Module/Install/Can.pm
inc/Module/Install/Fetch.pm
inc/Module/Install/Include.pm
inc/Module/Install/Makefile.pm
inc/Module/Install/Metadata.pm
inc/Module/Install/Win32.pm
inc/Module/Install/WriteAll.pm
inc/Test/Compile.pm
inc/Test/More.pm
lib/App/Benchmark.pm
Makefile.PL
MANIFEST This list of files
META.yml
README
t/00_compile.t
t/00_perl_critic.t
t/00_pod.t
t/benchmark.t
t/perlcriticrc
39 changes: 39 additions & 0 deletions MANIFEST.SKIP
@@ -0,0 +1,39 @@
# Version control files and dirs.
\bRCS\b
\bCVS\b
.svn
,v$

# Makemaker/Build.PL generated files and dirs.
^MANIFEST\.
^Makefile$
^Build$
^blib/
^pm_to_blib/
^_build/
^MakeMaker-\d
embedded/
cover_db/
smoke.html
smoke.yaml
smoketee.txt
sqlnet.log
BUILD.SKIP
COVER.SKIP
CPAN.SKIP
t/000_standard__*

# Temp, old, emacs, vim, backup files.
~$
\.old$
\.swp$
\.tar$
\.tar\.gz$
^#.*#$
^\.#
.shipit

# Local files, not to be included
^scratch/
core
^var/
19 changes: 19 additions & 0 deletions Makefile.PL
@@ -0,0 +1,19 @@
use inc::Module::Install;
include 'Module::AutoInstall';

name 'App-Benchmark';
all_from 'lib/App/Benchmark.pm';
perl_version '5.006';

requires 'Benchmark';
requires 'IO::Capture::Stdout';

recommends 'Test::Pod';
recommends 'Test::Pod::Coverage';

test_requires 'Test::More' => '0.70';
test_requires 'Test::Compile';

auto_install;
auto_include;
WriteAll;
27 changes: 27 additions & 0 deletions README
@@ -0,0 +1,27 @@
This is the Perl distribution App-Benchmark.

INSTALLATION

App-Benchmark installation is straightforward. If your CPAN shell is
set up, you should just be able to do

% cpan App::Benchmark

Download it, unpack it, then build it as per the usual:

% perl Makefile.PL
% make && make test

Then install it:

% make install

DOCUMENTATION

App-Benchmark documentation is available as in POD. So you can do:

% perldoc App::Benchmark

to read the documentation online with your favorite pager.

Marcel Gruenauer
109 changes: 109 additions & 0 deletions lib/App/Benchmark.pm
@@ -0,0 +1,109 @@
package App::Benchmark;

use strict;
use warnings;
use Test::More;
use Benchmark qw(cmpthese timethese :hireswallclock);
use IO::Capture::Stdout;


our $VERSION = '0.01';


use base 'Exporter';


our %EXPORT_TAGS = (
util => [ qw/benchmark_diag/ ],
);

our @EXPORT_OK = @{ $EXPORT_TAGS{all} = [ map { @$_ } values %EXPORT_TAGS ] };


sub benchmark_diag {
my ($iterations, $benchmark_hash) = @_;
my $capture = IO::Capture::Stdout->new;

$capture->start;
cmpthese(timethese($iterations, $benchmark_hash));
$capture->stop;

print "# $_" for $capture->read;
plan tests => 1;
pass('benchmark');
}


1;


__END__
=head1 NAME
App::Benchmark - Output your benchmarks as test diagnostics
=head1 SYNOPSIS
# This is t/benchmark.t:
use App::Benchmark ':all';
benchmark_diag(2_000_000, {
sqrt => sub { sqrt(2) },
log => sub { log(2) },
});
=head1 DESCRIPTION
This module makes it easy to run your benchmarks in a distribution's test
suite. This way you just have to look at the CPAN testers reports to see your
benchmarks being run on many different platforms using many different versions
of perl.
=head1 EXPORTS
Nothing is exported automatically. The function can be exported using its name
or the C<:all> tag.
=over 4
=item benchmark_diag
Takes a number of iterations and a benchmark definition hash, just like
C<timethese()> from the L<Benchmark> module. Runs the benchmarks and reports
them, each line prefixed by a hash sign so it doesn't mess up the TAP output.
Also, a pseudotest is being generated to keep the testing framework happy.
=back
=head1 BUGS AND LIMITATIONS
No bugs have been reported.
Please report any bugs or feature requests through the web interface at
L<http://rt.cpan.org>.
=head1 INSTALLATION
See perlmodinstall for information and options on installing Perl modules.
=head1 AVAILABILITY
The latest version of this module is available from the Comprehensive Perl
Archive Network (CPAN). Visit <http://www.perl.com/CPAN/> to find a CPAN
site near you. Or see <http://www.perl.com/CPAN/authors/id/M/MA/MARCEL/>.
=head1 AUTHORS
Marcel GrE<uuml>nauer, C<< <marcel@cpan.org> >>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Marcel GrE<uuml>nauer
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
13 changes: 13 additions & 0 deletions t/00_compile.t
@@ -0,0 +1,13 @@
#!perl -w

use strict;
use warnings;

BEGIN {
use Test::More;
eval "use Test::Compile";
Test::More->builder->BAIL_OUT(
"Test::Compile required for testing compilation") if $@;
all_pm_files_ok();
}

27 changes: 27 additions & 0 deletions t/00_perl_critic.t
@@ -0,0 +1,27 @@
#!perl -w

use strict;
use warnings;

use FindBin '$Bin';
use File::Spec;
use UNIVERSAL::require;
use Test::More;

plan skip_all =>
'Author test. Set $ENV{TEST_AUTHOR} to a true value to run.'
unless $ENV{TEST_AUTHOR};

my %opt;
my $rc_file = File::Spec->catfile($Bin, 'perlcriticrc');
$opt{'-profile'} = $rc_file if -r $rc_file;

if (Perl::Critic->require('1.078') &&
Test::Perl::Critic->require &&
Test::Perl::Critic->import(%opt)) {

all_critic_ok("lib");
} else {
plan skip_all => $@;
}

10 changes: 10 additions & 0 deletions t/00_pod.t
@@ -0,0 +1,10 @@
#!perl -w

use strict;
use warnings;

use Test::More;
eval "use Test::Pod";
plan skip_all => "Test::Pod required for testing POD" if $@;
all_pod_files_ok();

11 changes: 11 additions & 0 deletions t/benchmark.t
@@ -0,0 +1,11 @@
#!/usr/bin/env perl

use warnings;
use strict;
use App::Benchmark ':all';

benchmark_diag(2_000_000, {
sqrt => sub { sqrt(2) },
log => sub { log(2) },
});

12 changes: 12 additions & 0 deletions t/perlcriticrc
@@ -0,0 +1,12 @@
# no strict 'refs'
[TestingAndDebugging::ProhibitNoStrict]
allow = refs

[-BuiltinFunctions::ProhibitStringyEval]
[-ControlStructures::ProhibitMutatingListFunctions]
[-Subroutines::ProhibitExplicitReturnUndef]
[-Subroutines::ProhibitSubroutinePrototypes]
[-Variables::ProhibitConditionalDeclarations]

# for mkdir $dir, 0777
[-ValuesAndExpressions::ProhibitLeadingZeros]

0 comments on commit 9fb517f

Please sign in to comment.