NAME

Simple::Timer - Yet another simple timer

VERSION

This document describes version 0.01 of Simple::Timer (from Perl distribution Simple-Timer), released on 2015-04-29.

SYNOPSIS

use Simple::Timer; # exports timer() and $TIMER

# pick your preferred interface. either ...
$TIMER = 0; do_something(); say $TIMER;

# or ...
timer { do_something_else() }; # prints elapsed time

DESCRIPTION

This module offers yet another way (actually two ways) to time your code. The goal of this module is very simple interface, so no cumbersombe OO with the need to instantiate a class. You just use a single variable or a single function.

There are two ways which you can choose. You can either:

Use a special (tied) variable $TIMER. This variable is a stopwatch that starts running when you load the module. At the top of the portion of code you want to time, reset $TIMER to 0. Then at the bottom of the code, you read the value of $TIMER to get elapsed time.

Or alternatively you can also use the timer function. Just enclose the code you want to time with this function and at the end the elapsed time is printed.

Using the timer function is simpler, but it introduces another scope so you can't always use it. That's why there's an alternative $TIMER method.

EXPORTS

$TIMER => float

A tied variable that contains a running stopwatch. You can read its value to get elapsed time, or you can also set its value (usually reset it to 0).

FUNCTIONS

timer CODE

Execute CODE and print the number of seconds passed.

SEE ALSO

Benchmark modules which I often use: Benchmark, Benchmark::Dumb, Bench

To time whole programs simply, you might want to try Bench (just use/load it).

For alternatives to this module, you can try: Time::HiRes directly, Time::Stopwatch (the backend module which this module uses), Timer::Simple (OO), Devel::Timer (OO).

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Simple-Timer.

SOURCE

Source repository is at https://github.com/perlancar/perl-Simple-Timer.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Simple-Timer

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.