Commit b65fb00e authored by Martina Ferrari's avatar Martina Ferrari

Fixing tag names

parents
Stopwatch.pm
MANIFEST
Makefile.PL
test.pl
README
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
'NAME' => 'Time::Stopwatch',
'VERSION_FROM' => 'Stopwatch.pm',
'PREREQ_PM' => {}, # Time::HiRes is recommended
($] < 5.005 ? () :
(ABSTRACT_FROM => 'Stopwatch.pm',
AUTHOR => 'Ilmari Karonen <perl@itz.pp.sci.fi>')),
'dist' => {COMPRESS => 'gzip', SUFFIX => 'gz'}
);
Time::Stopwatch -- version 0.03
The Time::Stopwatch module provides a convenient interface to timing
functions through tied scalars. From the point of view of the user,
scalars tied to the module simply increase their value by one every
second.
Installing the Time::HiRes module lets Time::Stopwatch timers provide
sub-second accuracy. This feature will be automatically enabled if
Time::HiRes is present.
To install, just do:
perl Makefile.PL
make
make test
make install
If Time::HiRes is not installed, some tests will be skipped.
Alternatively you may simply put Stopwatch.pm in a subdirectory Time
wherever you like to keep your perl modules.
Copyright (c) 2000-2001 Ilmari Karonen. All rights reserved. This
library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
Address bug reports and comments to: perl@itz.pp.sci.fi
package Time::Stopwatch;
$VERSION = '1.00';
# POD documentation after __END__ below
use strict;
use constant HIRES => eval { local $SIG{__DIE__}; require Time::HiRes };
sub TIESCALAR {
my $pkg = shift;
my $time = (HIRES ? Time::HiRes::time() : time()) - (@_ ? shift() : 0);
bless \$time, $pkg;
}
sub FETCH { (HIRES ? Time::HiRes::time() : time()) - ${$_[0]}; }
sub STORE { ${$_[0]} = (HIRES ? Time::HiRes::time() : time()) - $_[1]; }
"That's all, folks!"
__END__
=head1 NAME
Time::Stopwatch - Use tied scalars as timers
=head1 SYNOPSIS
use Time::Stopwatch;
tie my $timer, 'Time::Stopwatch';
do_something();
print "Did something in $timer seconds.\n";
my @times = map {
$timer = 0;
do_something_else();
$timer;
} 1 .. 5;
=head1 DESCRIPTION
The Time::Stopwatch module provides a convenient interface to
timing functions through tied scalars. From the point of view of the
user, scalars tied to the module simply increase their value by one
every second.
Using the module should mostly be obvious from the synopsis. You can
provide an initial value for the timers either by assigning to them or
by passing the value as a third argument to tie().
If you have the module Time::HiRes installed, the timers created by
Time::Stopwatch will automatically count fractional seconds. Do
I<not> assume that the values of the timers are always integers. You
may test the constant C<Time::Stopwatch::HIRES> to find out whether
high resolution timing is enabled.
=head2 A note on timing short intervals
Time::Stopwatch is primarily designed for timing moderately long
intervals (i.e. several seconds), where the overhead imposed by the
tie() interface does not matter. With Time::HiRes installed, it can
nonetheless be used for even microsecond timing, provided that
appropriate care is taken.
=over 4
=item *
Explicitly initialize the timer by assignment. The first measurement
taken before resetting the timer will be a few microseconds longer due
to the overhead of the tie() call.
=item *
B<Always> subtract the overhead of the timing code. This is true in
general even if you're not using Time::Stopwatch. (High-level
benchmarking tools like Benchmark.pm do this automatically.) See the
code example below.
=item *
Take as many measurements as you can to minimize random errors. The
Statistics::Descriptive module may be useful for analyzing the data.
This advice is also true for all benchmarking.
=item *
Remember that a benchmark measures the time take to run the benchmark.
Any generalizations to real applications may or may not be valid. If
you want real world data, profile the real code in real use.
=back
The following sample code should give a relatively reasonable
measurement of a the time taken by a short operation:
use Time::HiRes; # high resolution timing required
use Time::Stopwatch;
use Statistics::Descriptive;
my $stat = Statistics::Descriptive::Sparse->new();
tie my $time, 'Time::Stopwatch'; # code timer
tie my $wait, 'Time::Stopwatch'; # loop timer
while ($wait < 60) { # run for one minute
my $diff = 0;
$time = 0; do_whatever(); $diff += $time;
$time = 0; $diff -= $time;
$stat->add_data($diff);
}
print("count: ", $stat->count(), " iterations\n",
"mean: ", $stat->mean(), " seconds\n",
"s.d.: ", $stat->standard_deviation(), " seconds\n");
Note that the above code includes the time of the subroutine call in
the measurement.
=head1 BUGS
Since tied scalars do not (yet?) support atomic modification, use of
operators like C<$t++> or C<$t *= 2> on timers will cause them to lose
the time it takes to fetch, modify and store the value. I I<might> be
able to get around this by overloading the return value of C<FETCH>,
but I doubt if it's worth the trouble. Just don't do that.
There is no way to force low-resolution timing if Time::HiRes has been
installed. I'm not sure why anyone would want to, since int() will do
just fine if you want whole seconds, but still..
=head1 CHANGE LOG
=over 4
=item 1.00 (15 Mar 2001)
Explicitly localized C<$SIG{__DIE__}> when testing for Time::HiRes
availability. Added "A note on timing short intervals" to the POD
documentation. Bumped version to 1, no longer beta.
=item 0.03 (27 Feb 2001)
Modified tests to give more information, reduced subsecond accuracy
test to 1/10 seconds to allow for inaccurate select() implementations.
Tweaked synopsis and README.
=back
=head1 SEE ALSO
Time::HiRes, L<perlfunc/tie>
For a higher-level approach to timing, try (among others) the modules
Time::SoFar, Devel::Timer, or Benchmark. Also see the profiling
modules Devel::DProf, Devel::SmallProf and Devel::OpProf.
=head1 AUTHORS
Copyright 2000-2001, Ilmari Karonen. All rights reserved.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
Address bug reports and comments to: perl@itz.pp.sci.fi
=cut
libtime-stopwatch-perl (1.00-1) unstable; urgency=low
* Initial Release (Closes: #309575)
* Maintainer -
Debian Perl Group <pkg-perl-maintainer@lists.alioth.debian.org>
via Carlo Segre <segre@iit.edu>
-- Carlo Segre <segre@iit.edu> Fri, 13 May 2005 21:36:04 -0500
Source: libtime-stopwatch-perl
Section: perl
Priority: optional
Maintainer: Debian Perl Group <pkg-perl-maintainers@lists.alioth.debian.org>
Uploaders: Carlo Segre <segre@iit.edu>, Gustavo Franco <stratus@debian.org>
Build-Depends: debhelper (>= 4.0.2)
Build-Depends-Indep: perl (>= 5.8.0-7)
Standards-Version: 3.6.1
Package: libtime-stopwatch-perl
Architecture: all
Depends: ${perl:Depends}
Description: Use tied scalars as timers
The Time::Stopwatch module provides a convenient interface to
timing functions through tied scalars. From the point of view of the
user, scalars tied to the module simply increase their value by one
every second.
This is the debian package for the Time::Stopwatch module.
It was created by Carlo Segre <segre@iit.edu> using dh-make-perl.
Upstream Author: Ilmari Karonen
Copyright 2000-2001, Ilmari Karonen. All rights reserved.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
Address bug reports and comments to: perl@itz.pp.sci.fi.
On Debian GNU/Linux systems, the complete text of these licenses can be found
in /usr/share/common-licenses/GPL and /usr/share/common-licenses/Artistic.
#!/usr/bin/make -f
# This debian/rules file is provided as a template for normal perl
# packages. It was created by Marc Brockschmidt <marc@dch-faq.de> for
# the Debian Perl Group (http://pkg-perl.alioth.debian.org/) but may
# be used freely wherever it is useful.
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
# If set to a true value then MakeMaker's prompt function will
# always return the default without waiting for user input.
export PERL_MM_USE_DEFAULT=1
PACKAGE=$(shell dh_listpackages)
ifndef PERL
PERL = /usr/bin/perl
endif
TMP =$(CURDIR)/debian/$(PACKAGE)
build: build-stamp
build-stamp:
dh_testdir
# Add commands to compile the package here
$(PERL) Makefile.PL INSTALLDIRS=vendor
$(MAKE) OPTIMIZE="-Wall -O2 -g"
touch build-stamp
clean:
dh_testdir
dh_testroot
# Add commands to clean up after the build process here
-$(MAKE) distclean
dh_clean build-stamp install-stamp
install: build install-stamp
install-stamp:
dh_testdir
dh_testroot
dh_clean -k
# Add commands to install the package into debian/$PACKAGE_NAME here
$(MAKE) test
$(MAKE) install DESTDIR=$(TMP) PREFIX=/usr
# As this is a architecture independent package, we are not
# supposed to install stuff to /usr/lib. MakeMaker creates
# the dirs, we delete them from the deb:
rmdir --ignore-fail-on-non-empty --parents $(TMP)/usr/lib/perl5
touch install-stamp
binary-arch:
# We have nothing to do by default.
binary-indep: build install
dh_testdir
dh_testroot
# dh_installcron
# dh_installmenu
# dh_installexamples
dh_installdocs README
dh_installchangelogs
dh_perl
dh_link
dh_strip
dh_compress
dh_fixperms
dh_installdeb
dh_gencontrol
dh_md5sums
dh_builddeb
source diff:
@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false
binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary
version=2
http://www.cpan.org/modules/by-module/Time/Time-Stopwatch-(.*)\.tar\.gz debian
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
######################### We start with some black magic to print on failure.
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
BEGIN { $| = 1; print "1..9\n"; }
END {print "not ok 1\n" unless $loaded;}
use Time::Stopwatch;
$loaded = 1;
print "ok 1\n";
######################### End of black magic.
# Insert your test code below (better if it prints "ok 13"
# (correspondingly "not ok 13") depending on the success of chunk 13
# of the test code):
print <<"NOTE" unless Time::Stopwatch::HIRES;
! As Time::HiRes could not be loaded, resolution will be !
! limited to one second. Some tests will be skipped. !
NOTE
# Does the timer work at all?
test2: {
tie my $timer, 'Time::Stopwatch';
my $start = $timer;
sleep(1);
my $stop = $timer;
print $start < $stop ? "ok" : "not ok",
" 2\t# $start < $stop\n";
};
# Can we supply an initial value?
test3: {
tie my $timer, 'Time::Stopwatch', 32;
my $stop = $timer;
print $stop >= 32 ? "ok" : "not ok",
" 3\t# $stop >= 32\n";
};
# How about assignment?
test4: {
tie my $timer, 'Time::Stopwatch';
$timer = 64;
my $stop = $timer;
print $stop >= 64 ? "ok" : "not ok",
" 4\t# $stop >= 64\n";
};
# Are fractional times preserved?
test5: {
tie my $timer, 'Time::Stopwatch', 2.5;
my $stop = $timer;
print $stop != int($stop) ? "ok" : "not ok",
" 5\t# $stop != ${\int($stop)}\n";
};
# Can we do real fractional timing?
test6: {
print "ok 6\t# skipped, no Time::HiRes\n"
and next unless Time::Stopwatch::HIRES;
tie my $timer, 'Time::Stopwatch', 1;
select(undef,undef,undef,0.25);
my $stop = $timer;
print $stop != int($stop) ? "ok" : "not ok",
" 6\t# $stop != ${\int($stop)}\n";
};
# Is it accurate to one second?
test7: {
tie my $timer, 'Time::Stopwatch', 2;
sleep(2);
my $stop = $timer;
print int($stop+.5) == 4 ? "ok" : "not ok",
" 7\t# 3.5 <= $stop < 4.5\n";
};
# Is it accurate to 1/10 seconds?
test8: {
print "ok 8\t# skipped, no Time::HiRes\n"
and next unless Time::Stopwatch::HIRES;
tie my $timer, 'Time::Stopwatch';
select(undef,undef,undef,1.3);
my $stop = $timer;
print int(10*$stop+.5) == 13 ? "ok" : "not ok",
" 8\t# 1.25 <= $stop < 1.35\n";
};
# Does $t++ really make the timer lag?
test9: {
print "ok 9\t# skipped, no Time::HiRes\n"
and next unless Time::Stopwatch::HIRES;
tie my $timer, 'Time::Stopwatch';
tie my $delay, 'Time::Stopwatch';
while ($delay < 1) { $timer++; $timer--; }
my $stop = $timer;
print $stop < 1 ? "ok" : "not ok",
" 9\t# $stop < 1 (confirms known bug)\n";
};
__END__
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment