{"id":18909992,"url":"https://github.com/jonasbn/perl-test-timer","last_synced_at":"2025-04-15T06:31:05.141Z","repository":{"id":12319187,"uuid":"14955068","full_name":"jonasbn/perl-test-timer","owner":"jonasbn","description":"Test::Timer - test module to test/assert response times","archived":false,"fork":false,"pushed_at":"2025-04-07T10:50:13.000Z","size":754,"stargazers_count":1,"open_issues_count":11,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T04:48:46.087Z","etag":null,"topics":["hacktoberfest","perl","perl-module","perl5","test","testing","timing"],"latest_commit_sha":null,"homepage":"https://jonasbn.github.io/perl-test-timer/","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonasbn.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-12-05T14:04:24.000Z","updated_at":"2025-04-07T10:50:17.000Z","dependencies_parsed_at":"2023-11-20T07:58:43.605Z","dependency_job_id":"a5d27cee-2170-40e8-bbb6-c89d923782a3","html_url":"https://github.com/jonasbn/perl-test-timer","commit_stats":{"total_commits":391,"total_committers":12,"mean_commits":"32.583333333333336","dds":"0.30179028132992325","last_synced_commit":"b3ab227a084c2dae22261e623cde6eea187d7ac0"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonasbn%2Fperl-test-timer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonasbn%2Fperl-test-timer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonasbn%2Fperl-test-timer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonasbn%2Fperl-test-timer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonasbn","download_url":"https://codeload.github.com/jonasbn/perl-test-timer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249020728,"owners_count":21199607,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","perl","perl-module","perl5","test","testing","timing"],"created_at":"2024-11-08T09:38:55.066Z","updated_at":"2025-04-15T06:31:04.446Z","avatar_url":"https://github.com/jonasbn.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Test::Timer\n\n[![CPAN version](https://badge.fury.io/pl/Test-Timer.svg)](http://badge.fury.io/pl/Test-Timer)\n![stability-stable](https://img.shields.io/badge/stability-stable-green.svg)\n[![Build Status](https://travis-ci.org/jonasbn/perl-test-timer.svg?branch=master)](https://travis-ci.org/jonasbn/perl-test-timer)\n[![Coverage Status](https://coveralls.io/repos/github/jonasbn/perl-test-timer/badge.svg?branch=master)](https://coveralls.io/github/jonasbn/perl-test-timer?branch=master)\n[![License: Artistic-2.0](https://img.shields.io/badge/License-Artistic%202.0-0298c3.svg)](https://opensource.org/licenses/Artistic-2.0)\n[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/1391/badge)](https://bestpractices.coreinfrastructure.org/projects/1391)\n\n\u003c!-- MarkdownTOC bracket=round levels=\"1,2,3,4,5\" indent=\"  \" --\u003e\n\n- [NAME](#name)\n- [VERSION](#version)\n- [FEATURES](#features)\n- [SYNOPSIS](#synopsis)\n- [DESCRIPTION](#description)\n- [EXPORT](#export)\n- [SUBROUTINES/METHODS](#subroutinesmethods)\n  - [time\\_ok](#time_ok)\n  - [time\\_nok](#time_nok)\n  - [time\\_atmost](#time_atmost)\n  - [time\\_atleast](#time_atleast)\n  - [time\\_between](#time_between)\n- [PRIVATE FUNCTIONS](#private-functions)\n  - [\\_runtest](#_runtest)\n  - [\\_benchmark](#_benchmark)\n  - [import](#import)\n- [DIAGNOSTICS](#diagnostics)\n- [CONFIGURATION AND ENVIRONMENT](#configuration-and-environment)\n- [DEPENDENCIES](#dependencies)\n- [INCOMPATIBILITIES](#incompatibilities)\n- [BUGS AND LIMITATIONS](#bugs-and-limitations)\n- [TEST AND QUALITY](#test-and-quality)\n  - [CONTINUOUS INTEGRATION](#continuous-integration)\n- [SEE ALSO](#see-also)\n- [ISSUE REPORTING](#issue-reporting)\n- [SUPPORT](#support)\n- [DEVELOPMENT](#development)\n- [AUTHOR](#author)\n- [ACKNOWLEDGEMENTS](#acknowledgements)\n- [LICENSE AND COPYRIGHT](#license-and-copyright)\n\n\u003c!-- /MarkdownTOC --\u003e\n\n# NAME\n\nTest::Timer - test module to test/assert response times\n\n# VERSION\n\nThe documentation describes version 2.12 of Test::Timer\n\n# FEATURES\n\n- Test subroutines to implement unit-tests to time that your code executes before a specified threshold\n- Test subroutines to implement unit-tests to time that your code execution exceeds a specified threshold\n- Test subroutine to implement unit-tests to time that your code executes within a specified time frame\n- Supports measurements in seconds\n- Implements configurable alarm signal handler to make sure that your tests do not execute forever\n\n# SYNOPSIS\n\n    use Test::Timer;\n\n    time_ok( sub { doYourStuffButBeQuickAboutIt(); }, 1, 'threshold of one second');\n\n    time_atmost( sub { doYourStuffYouHave10Seconds(); }, 10, 'threshold of 10 seconds');\n\n    time_between( sub { doYourStuffYouHave5-10Seconds(); }, 5, 10,\n        'lower threshold of 5 seconds and upper threshold of 10 seconds');\n\n    # Will succeed\n    time_nok( sub { sleep(2); }, 1, 'threshold of one second');\n\n    time_atleast( sub { sleep(2); }, 2, 'threshold of one second');\n\n    # Will fail after 5 (threshold) + 2 seconds (default alarm)\n    time_ok( sub { while(1) { sleep(1); } }, 5, 'threshold of one second');\n\n    $test::Timer::alarm = 6 #default 2 seconds\n\n    # Will fail after 5 (threshold) + 6 seconds (specified alarm)\n    time_ok( sub { while(1) { sleep(1); } }, 5, 'threshold of one second');\n\n# DESCRIPTION\n\nTest::Timer implements a set of test primitives to test and assert test times\nfrom bodies of code.\n\nThe key features are subroutines to assert or test the following:\n\n- that a given piece of code does not exceed a specified time limit\n- that a given piece of code takes longer than a specified time limit and does not exceed another\n\n# EXPORT\n\nTest::Timer exports:\n\n- [time\\_ok](#time_ok)\n- [time\\_nok](#time_nok)\n- [time\\_atleast](#time_atleast)\n- [time\\_atmost](#time_atmost)\n- [time\\_between](#time_between)\n\n# SUBROUTINES/METHODS\n\n## time\\_ok\n\nTakes the following parameters:\n\n- a reference to a block of code (anonymous sub)\n- a threshold specified as a integer indicating a number of seconds\n- a string specifying a test name\n\n    time_nok( sub { sleep(2); }, 1, 'threshold of one second');\n\nIf the execution of the code exceeds the threshold specified the test fail with the following diagnostic message\n\n    Test ran 2 seconds and exceeded specified threshold of 1 seconds\n\n## time\\_nok\n\nThe is the inverted variant of [time\\_ok](#time_ok), it passes if the threshold is\nexceeded and fails if the benchmark of the code is within the specified\ntiming threshold.\n\nThe API is the same as for [time\\_ok](#time_ok).\n\n    time_nok( sub { sleep(1); }, 2, 'threshold of two seconds');\n\nIf the execution of the code executes below the threshold specified the test fail with the following diagnostic message\n\n    Test ran 1 seconds and did not exceed specified threshold of 2 seconds\n\n## time\\_atmost\n\nThis is _syntactic sugar_ for [time\\_ok](#time_ok)\n\n    time_atmost( sub { doYourStuffButBeQuickAboutIt(); }, 1, 'threshold of one second');\n\nIf the execution of the code exceeds the threshold specified the test fail with the following diagnostic message\n\n    Test ran N seconds and exceeded specified threshold of 1 seconds\n\nN will be the actual measured execution time of the specified code\n\n![time_atmost visualization](https://jonasbn.github.io/perl-test-timer/assets/images/time_atmost.png)\n\n## time\\_atleast\n\n    time_atleast( sub { doYourStuffAndTakeYourTimeAboutIt(); }, 1, 'threshold of 1 second');\n\nThe test succeeds if the code takes at least the number of seconds specified by\nthe timing threshold.\n\nIf the code executes faster, the test fails with the following diagnostic message\n\n    Test ran 1 seconds and did not exceed specified threshold of 2 seconds\n\nPlease be aware that Test::Timer, breaks the execution with an alarm specified\nto trigger after the specified threshold + 2 seconds (default), so if you expect your\nexecution to run longer, set the alarm accordingly.\n\n    $Test::Timer::alarm = $my_alarm_in_seconds;\n\nSee also [diagnostics](#diagnostics).\n\n![time_atleast visualization](https://jonasbn.github.io/perl-test-timer/assets/images/time_atleast.png)\n\n## time\\_between\n\nThis method is a more extensive variant of [time\\_atmost](#time_atmost) and [time\\_ok](#time_ok), you\ncan specify a lower and upper threshold, the code has to execute within this\ninterval in order for the test to succeed\n\n    time_between( sub { sleep(2); }, 5, 10,\n        'lower threshold of 5 seconds and upper threshold of 10 seconds');\n\nIf the code executes faster than the lower threshold or exceeds the upper threshold, the test fails with the following diagnostic message\n\n    Test ran 2 seconds and did not execute within specified interval 5 - 10 seconds\n\nOr\n\n    Test ran 12 seconds and did not execute within specified interval 5 - 10 seconds\n\n![time_between visualization](https://jonasbn.github.io/perl-test-timer/assets/images/time_between.png)\n\n# PRIVATE FUNCTIONS\n\n## \\_runtest\n\nThis is a method to handle the result from [\\_benchmark](#_benchmark) is initiates the\nbenchmark calling benchmark and based on whether it is within the provided\ninterval true (1) is returned and if not false (0).\n\n## \\_benchmark\n\nThis is the method doing the actual benchmark, if a better method is located\nthis is the place to do the handy work.\n\nCurrently [Benchmark](https://metacpan.org/pod/Benchmark) is used. An alternative could be [Devel::Timer](https://metacpan.org/pod/Devel%3A%3ATimer), but I\ndo not know this module very well and [Benchmark](https://metacpan.org/pod/Benchmark) is core, so this is used for\nnow.\n\nThe method takes two parameters:\n\n- a code block via a code reference\n- a threshold (the upper threshold, since this is added to the default alarm\n\n## import\n\nTest::Builder required import to do some import _hokus-pokus_ for the test methods\nexported from Test::Timer. Please refer to the documentation in [Test::Builder](https://metacpan.org/pod/Test%3A%3ABuilder)\n\n# DIAGNOSTICS\n\nAll tests either fail or succeed, but a few exceptions are implemented, these\nare listed below.\n\n- Test did not exceed specified threshold, this message is diagnosis for [time\\_atleast](#time_atleast) and [time\\_nok](#time_nok) tests, which do not exceed their specified threshold\n- Test exceeded specified threshold, this message is a diagnostic for [time\\_atmost](#time_atmost) and [time\\_ok](#time_ok), if the specified threshold is surpassed.\n\n    This is the key point of the module, either your code is too slow and you should\n    address this or your threshold is too low, in which case you can set it a bit\n    higher and run the test again.\n\n- Test did not execute within specified interval, this is the diagnostic from [time\\_between](#time_between), it is the diagnosis if the execution of the code is not between the specified lower and upper thresholds\n- Insufficient parameters, this is the message if a specified test is not provided with the sufficient number of parameters, consult this documentation and correct accordingly\n- Execution exceeded threshold and timed out, the exception is thrown if the execution of tested code exceeds even the alarm, which is default 2 seconds, but can be set by the user or is equal to the upper threshold + 2 seconds\n\n    The exception results in a diagnostic for the failing test. This is a fail-safe\n    to avoid that code runs forever. If you get this diagnose either your code is\n    too slow and you should address this or it might be error prone. If this is not\n    the case adjust the alarm setting to suit your situation.\n\n# CONFIGURATION AND ENVIRONMENT\n\nThis module requires no special configuration or environment.\n\nTests are sensitive and be configured using environment and configuration files, please\nsee the section on [test and quality](#test-and-quality).\n\n# DEPENDENCIES\n\n- [Carp](https://metacpan.org/pod/Carp)\n- [Benchmark](https://metacpan.org/pod/Benchmark)\n- [Error](https://metacpan.org/pod/Error)\n- [Test::Builder](https://metacpan.org/pod/Test%3A%3ABuilder)\n- [Test::Builder::Module](https://metacpan.org/pod/Test%3A%3ABuilder%3A%3AModule)\n\n# INCOMPATIBILITIES\n\nThis module holds no known incompatibilities.\n\n# BUGS AND LIMITATIONS\n\nThis module holds no known bugs.\n\nThe current implementations only use seconds and resolutions should be higher,\nso the current implementation is limited to seconds as the highest resolution.\n\nOn occasion failing tests with CPAN-testers have been observed. This seem to be related to the test-suite\nbeing not taking into account that some smoke-testers do not prioritize resources for the test run and that\nadditional processes/jobs are running. The test-suite have been adjusted to accommodate this but these issues\nmight reoccur.\n\n# TEST AND QUALITY\n\n[![Coverage Status](https://coveralls.io/repos/github/jonasbn/perl-test-timer/badge.svg?branch=master)](https://coveralls.io/github/jonasbn/perl-test-timer?branch=master)\n\nCoverage report for the release described in this documentation (see [VERSION](#version)).\n\n    ---------------------------- ------ ------ ------ ------ ------ ------ ------\n    File                           stmt   bran   cond    sub    pod   time  total\n    ---------------------------- ------ ------ ------ ------ ------ ------ ------\n    blib/lib/Test/Timer.pm        100.0  100.0  100.0  100.0  100.0   99.9  100.0\n    ...Timer/TimeoutException.pm  100.0    n/a    n/a  100.0  100.0    0.0  100.0\n    Total                         100.0  100.0  100.0  100.0  100.0  100.0  100.0\n    ---------------------------- ------ ------ ------ ------ ------ ------ ------\n\nThe [Test::Perl::Critic](https://metacpan.org/pod/Test%3A%3APerl%3A%3ACritic) test runs with severity 5 (gentle) for now, please\nrefer to `t/critic.t` and `t/perlcriticrc`.\n\nSet TEST\\_POD to enable [Test::Pod](https://metacpan.org/pod/Test%3A%3APod) test in `t/pod.t` and [Test::Pod::Coverage](https://metacpan.org/pod/Test%3A%3APod%3A%3ACoverage)\ntest in `t/pod-coverage.t`.\n\nSet TEST\\_CRITIC to enable [Test::Perl::Critic](https://metacpan.org/pod/Test%3A%3APerl%3A%3ACritic) test in `t/critic.t`\n\n## CONTINUOUS INTEGRATION\n\nThis distribution uses Travis for continuous integration testing, the\nTravis reports are public available.\n\n[![Build Status](https://travis-ci.org/jonasbn/perl-test-timer.svg?branch=master)](https://travis-ci.org/jonasbn/perl-test-timer)\n\n# SEE ALSO\n\n- [Test::Benchmark](https://metacpan.org/pod/Test%3A%3ABenchmark)\n\n# ISSUE REPORTING\n\nPlease report any bugs or feature requests using GitHub\n\n- [GitHub Issues](https://github.com/jonasbn/perl-test-timer/issues)\n\n# SUPPORT\n\nYou can find (this) documentation for this module with the `perldoc` command.\n\n    perldoc Test::Timer\n\nYou can also look for information at:\n\n- [Homepage](https://jonasbn.github.io/perl-test-timer/)\n- [MetaCPAN](https://metacpan.org/pod/Test-Timer)\n- [AnnoCPAN: Annotated CPAN documentation](http://annocpan.org/dist/Test-Timer)\n- [CPAN Ratings](http://cpanratings.perl.org/d/Test-Timer)\n\n# DEVELOPMENT\n\n- [GitHub Repository](https://github.com/jonasbn/perl-test-timer), please see [the guidelines for contributing](https://github.com/jonasbn/perl-test-timer/blob/master/CONTRIBUTING.md).\n\n# AUTHOR\n\n- Jonas Brømsø (jonasbn) `\u003cjonasbn at cpan.org\u003e`\n\n# ACKNOWLEDGEMENTS\n\n- Mohammad S Anwar (MANWAR), POD corrections PRs #23\n- Erik Johansen (UNIEJO), suggestion for clearing alarm\n- Gregor Herrmann (GREGOA) from the Debian Perl Group, PR #16 fixes to spelling mistakes\n- Nigel Horne (NHORNE), issue #15 suggestion for better assertion in [time\\_atleast](#time_atleast)\n- Nigel Horne (NHORNE), issue #10/#12 suggestion for improvement to diagnostics\n- p-alik, PR #4 eliminating warnings during test\n- Kent Fredric (KENTNL), PR #7 addressing file permissions\n- Nick Morrott, PR #5 corrections to POD\n- Bartosz Jakubski, reporting issue #3\n- Gabor Szabo (SZABGAB), suggestion for specification of interval thresholds even though this was obsoleted by the later introduced time\\_between\n- Paul Leonerd Evans (PEVANS), suggestions for time\\_atleast and time\\_atmost and the handling of $SIG{ALRM}. Also bug report for addressing issue with Debian packaging resulting in release 0.10\n- brian d foy (BDFOY), for patch to [\\_runtest](#_runtest)\n\n# LICENSE AND COPYRIGHT\n\nTest::Timer and related modules are (C) by Jonas Brømsø\n(jonasbn) 2007-2021\n\nTest::Timer and related modules are released under the Artistic\nLicense 2.0\n\nUsed distributions are under copyright of there respective authors and designated licenses\n\nImage used on [website](https://jonasbn.github.io/perl-test-timer/) is under copyright by [Veri Ivanova](https://unsplash.com/photos/p3Pj7jOYvnM)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonasbn%2Fperl-test-timer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonasbn%2Fperl-test-timer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonasbn%2Fperl-test-timer/lists"}