diff --git a/.shipit b/.shipit new file mode 100644 index 0000000..0763e12 --- /dev/null +++ b/.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 + + diff --git a/Changes b/Changes new file mode 100644 index 0000000..21913dd --- /dev/null +++ b/Changes @@ -0,0 +1,4 @@ +Revision history for Perl extension App-Benchmark + +0.01 2008-11-02T21:31:53Z (Marcel Gruenauer ) + - original version diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..82b63be --- /dev/null +++ b/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 diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP new file mode 100644 index 0000000..1ff3090 --- /dev/null +++ b/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/ diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..de70a25 --- /dev/null +++ b/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; diff --git a/README b/README new file mode 100644 index 0000000..ba36a22 --- /dev/null +++ b/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 diff --git a/lib/App/Benchmark.pm b/lib/App/Benchmark.pm new file mode 100644 index 0000000..c712d87 --- /dev/null +++ b/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 from the L 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. + +=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 to find a CPAN +site near you. Or see . + +=head1 AUTHORS + +Marcel GrEnauer, C<< >> + +=head1 COPYRIGHT AND LICENSE + +Copyright 2008 by Marcel GrEnauer + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + diff --git a/t/00_compile.t b/t/00_compile.t new file mode 100644 index 0000000..50c1271 --- /dev/null +++ b/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(); +} + diff --git a/t/00_perl_critic.t b/t/00_perl_critic.t new file mode 100644 index 0000000..8f24444 --- /dev/null +++ b/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 => $@; +} + diff --git a/t/00_pod.t b/t/00_pod.t new file mode 100644 index 0000000..5b5c72c --- /dev/null +++ b/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(); + diff --git a/t/benchmark.t b/t/benchmark.t new file mode 100644 index 0000000..46435ab --- /dev/null +++ b/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) }, +}); + diff --git a/t/perlcriticrc b/t/perlcriticrc new file mode 100644 index 0000000..f5ff3c7 --- /dev/null +++ b/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]