{"id":15014405,"url":"https://github.com/teqneers/phpunit-stopwatch","last_synced_at":"2026-02-09T17:01:24.143Z","repository":{"id":227853748,"uuid":"772577741","full_name":"teqneers/phpunit-stopwatch","owner":"teqneers","description":"A stopwatch extension for phpunit. Get timing for parts of your code to detect performance bottlenecks.","archived":false,"fork":false,"pushed_at":"2024-10-19T15:05:56.000Z","size":128,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-29T08:20:02.566Z","etag":null,"topics":["bottleneck","extension","measure","performance","phpunit","slow","stopwatch","test","time"],"latest_commit_sha":null,"homepage":"https://github.com/teqneers/phpunit-stopwatch","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/teqneers.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"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,"zenodo":null}},"created_at":"2024-03-15T13:22:58.000Z","updated_at":"2025-01-08T13:41:53.000Z","dependencies_parsed_at":"2024-03-18T14:50:20.787Z","dependency_job_id":"cecd4061-bd85-4e4c-a065-ec54e3df2983","html_url":"https://github.com/teqneers/phpunit-stopwatch","commit_stats":{"total_commits":72,"total_committers":1,"mean_commits":72.0,"dds":0.0,"last_synced_commit":"6d723948953f473bcb7811713f77b70b7c636cd0"},"previous_names":["teqneers/phpunit-stopwatch"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/teqneers/phpunit-stopwatch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teqneers%2Fphpunit-stopwatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teqneers%2Fphpunit-stopwatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teqneers%2Fphpunit-stopwatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teqneers%2Fphpunit-stopwatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teqneers","download_url":"https://codeload.github.com/teqneers/phpunit-stopwatch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teqneers%2Fphpunit-stopwatch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29273139,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-09T13:47:44.167Z","status":"ssl_error","status_checked_at":"2026-02-09T13:47:43.721Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["bottleneck","extension","measure","performance","phpunit","slow","stopwatch","test","time"],"created_at":"2024-09-24T19:45:35.473Z","updated_at":"2026-02-09T17:01:24.094Z","avatar_url":"https://github.com/teqneers.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# phpunit-stopwatch\n\n[![Latest Stable Version](https://poser.pugx.org/teqneers/phpunit-stopwatch/v)](https://packagist.org/packages/teqneers/phpunit-stopwatch)\n[![CI](https://github.com/teqneers/phpunit-stopwatch/actions/workflows/ci.yml/badge.svg)](https://github.com/teqneers/phpunit-stopwatch/actions)\n\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/teqneers/phpunit-stopwatch/badges/quality-score.png?b=main)](https://scrutinizer-ci.com/g/teqneers/phpunit-stopwatch/?branch=main)\n[![Code Coverage](https://scrutinizer-ci.com/g/teqneers/phpunit-stopwatch/badges/coverage.png?b=main)](https://scrutinizer-ci.com/g/teqneers/phpunit-stopwatch/?branch=main)\n[![Code Climate](https://codeclimate.com/github/teqneers/phpunit-stopwatch/badges/gpa.svg)](https://codeclimate.com/github/teqneers/phpunit-stopwatch)\n[![codecov](https://codecov.io/gh/teqneers/phpunit-stopwatch/graph/badge.svg?token=U1T7ZGW5XW)](https://codecov.io/gh/teqneers/phpunit-stopwatch)\n[![Type Coverage](https://shepherd.dev/github/teqneers/phpunit-stopwatch/coverage.svg)](https://shepherd.dev/github/teqneers/phpunit-stopwatch)\n\nProject\ninformation: [![License](https://img.shields.io/github/license/teqneers/phpunit-stopwatch.svg?style=flat)](https://img.shields.io/github/license/teqneers/phpunit-stopwatch.svg?style=flat)\n[![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/teqneers/phpunit-stopwatch.svg?style=flat)]((https://img.shields.io/github/languages/code-size/teqneers/phpunit-stopwatch.svg?style=flat))\n\nStopwatch is an essential [`phpunit/phpunit`](https://github.com/sebastianbergmann/phpunit) extension for performance\nanalysis!\n\nGain invaluable insights into your code's execution time and call frequency during test runs. The extension is designed\nto elevate your code performance analysis. Track the execution time and frequency of any marked code segments to address\nperformance bottlenecks with precision.\nYou can identify performance bottlenecks (e.g., database cleanups or setup) or just monitor them over time. The\nextension will generate stopwatch reports for each test as well as a summary report at the end of the test run.\n\nThis project provides a [`composer`](https://getcomposer.org) package and\na [Phar archive](https://www.php.net/manual/en/book.phar.php).\n\nThe extension is compatible with the following versions of `phpunit/phpunit`:\n\n- [`phpunit/phpunit:^10.1.0`](https://github.com/sebastianbergmann/phpunit/tree/10.1.0)\n- [`phpunit/phpunit:^11.0.0`](https://github.com/sebastianbergmann/phpunit/tree/11.0.0)\n\nOnce you've added some measurement points to your code, the extension will stop watch and count them. The results are\ndisplayed for each test and as a total report at the end of the test run.\n\nHere is an example of how the output of a single test class might look:\n\n```console\nStopwatch for TQ\\Tests\\Example\\SingleTest::testDataCalculation:\n- TQ\\Testing\\Database::deleteData      0.117secs (    3x, Ø   0.04) TOTAL    327.026secs (  184x, Ø   1.78)\n- ...onment\\Testing::cleanupInstance   0.259secs (    1x, Ø   0.26) TOTAL      6.159secs (   60x, Ø   0.10)\n- TQ\\Testing\\Database::import          7.889secs (   11x, Ø   0.72) TOTAL    250.958secs (  352x, Ø   0.71)\n- Test                                 1.428secs (    1x, Ø   1.43) TOTAL   1041.228secs (   70x, Ø  14.87)\n.\n\nStopwatch for TQ\\Tests\\Example\\SingleTest::testDataTransfer:\n- TQ\\Testing\\Database::deleteData      0.116secs (    3x, Ø   0.04) TOTAL    327.142secs (  187x, Ø   1.75)\n- ...onment\\Testing::cleanupInstance   0.256secs (    1x, Ø   0.26) TOTAL      6.415secs (   61x, Ø   0.11)\n- TQ\\Testing\\Database::import          7.573secs (   11x, Ø   0.69) TOTAL    258.531secs (  363x, Ø   0.71)\n- Test                                 5.998secs (    1x, Ø   6.00) TOTAL   1047.226secs (   71x, Ø  14.75)\n.\n\nStopwatch for TQ\\Tests\\Example\\SingleTest TearDown:\n- TQ\\Testing\\Database::deleteData     38.486secs (    6x, Ø   6.41) TOTAL    365.511secs (  190x, Ø   1.92)\n- ...onment\\Testing::cleanupInstance   0.256secs (    1x, Ø   0.26) TOTAL      6.415secs (   61x, Ø   0.11)\n- TQ\\Testing\\Database::import          7.573secs (   11x, Ø   0.69) TOTAL    258.531secs (  363x, Ø   0.71)\n- Test                                 5.998secs (    1x, Ø   6.00) TOTAL   1047.226secs (   71x, Ø  14.75)\n```\n\nAnd at the end of the test run, you will get a summary of all stopwatches used, and it is going to look like this:\n\n```console\nStopwatch TOTALS:\n- Test                                     TOTAL   1047.246secs (   78x, Ø  13.43)\n- TQ\\Testing\\Database::deleteData          TOTAL    365.511secs (  190x, Ø   1.92)\n- TQ\\Testing\\Database::import              TOTAL    258.531secs (  363x, Ø   0.71)\n- ...onment\\Testing::cleanupInstance       TOTAL      6.416secs (   62x, Ø   0.10)\n- TQ\\Production\\Monitoring::ping           TOTAL     17.967secs (    7x, Ø   2.57)\n```\n\n### Usage\n\nStopwatch is very easy to use. A single line of code wrapped around the code you want to measure is all it takes.\n\nFor instance, let's say your tests are pretty slow, but you don't know who's the culprit? You suspect that it might be\nthe\ndatabase setup that has to be done for each and every test. Simply wrap the suspected code block as follows:\n\n```php\n        Stopwatch::start(__METHOD__);\n\n        self::initializeDatabase(\n            $db-\u003egetConnection(),\n            ...static::createData()\n        );\n\n        Stopwatch::stop(__METHOD__);\n```\n\nShould the test, setup, teardown, or other relevant methods execute this code, Stopwatch will seamlessly measure its\nexecution time and count, and will present the results within the test output.\n\n## Installation\n\n### Installation with `composer`\n\nRun\n\n```sh\ncomposer require --dev teqneers/phpunit-stopwatch\n```\n\nto install `teqneers/phpunit-stopwatch` as a `composer` package.\n\n### Installation as Phar\n\nDownload `phpunit-stopwatch.phar` from\nthe [latest release](https://github.com/teqneers/phpunit-stopwatch/releases/latest).\n\n## Usage\n\n### Bootstrapping the extension\n\nBefore the extension can detect slow tests in `phpunit/phpunit`, you need to bootstrap it. The bootstrapping mechanism\ndepends on the version of `phpunit/phpunit` you are using.\n\n### Bootstrapping the extension as a `composer` package\n\nTo bootstrap the extension as a `composer` package when using\n\n- `phpunit/phpunit:^10.0.0`\n- `phpunit/phpunit:^11.0.0`\n\nadjust your `phpunit.xml` configuration file and configure the\n\n- [`extensions` element](https://docs.phpunit.de/en/10.5/configuration.html#the-extensions-element)\n  on [`phpunit/phpunit:^10.1.0`](https://docs.phpunit.de/en/10.5/)\n- [`extensions` element](https://docs.phpunit.de/en/11.0/configuration.html#the-extensions-element)\n  on [`phpunit/phpunit:^11.0.0`](https://docs.phpunit.de/en/11.0/)\n\n```diff\n \u003cphpunit\n     xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n     xsi:noNamespaceSchemaLocation=\"vendor/phpunit/phpunit/phpunit.xsd\"\n     bootstrap=\"vendor/autoload.php\"\n \u003e\n+    \u003cextensions\u003e\n+        \u003cbootstrap class=\"TQ\\Testing\\Extension\\Stopwatch\\Extension\"/\u003e\n+    \u003c/extensions\u003e\n     \u003ctestsuites\u003e\n         \u003ctestsuite name=\"unit\"\u003e\n             \u003cdirectory\u003etest/Unit/\u003c/directory\u003e\n         \u003c/testsuite\u003e\n     \u003c/testsuites\u003e\n \u003c/phpunit\u003e\n```\n\n### Bootstrapping the extension as a PHAR\n\nTo bootstrap the extension as a PHAR when using\n\n- `phpunit/phpunit:^10.1.0`\n- `phpunit/phpunit:^11.0.0`\n\nadjust your `phpunit.xml` configuration file and configure the\n\n- [`extensionsDirectory` attribute](https://docs.phpunit.de/en/10.5/configuration.html#the-extensionsdirectory-attribute)\n  and the [`extensions` element](https://docs.phpunit.de/en/10.5/configuration.html#the-extensions-element)\n  on [`phpunit/phpunit:^10.0.0`](https://docs.phpunit.de/en/10.5/)\n- [`extensionsDirectory` attribute](https://docs.phpunit.de/en/11.0/configuration.html#the-extensionsdirectory-attribute)\n  and the [`extensions` element](https://docs.phpunit.de/en/11.0/configuration.html#the-extensions-element)\n  on [`phpunit/phpunit:^11.0.0`](https://docs.phpunit.de/en/11.0/)\n\n```diff\n \u003cphpunit\n     xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n     xsi:noNamespaceSchemaLocation=\"vendor/phpunit/phpunit/phpunit.xsd\"\n     bootstrap=\"vendor/autoload.php\"\n+    extensionsDirectory=\"directory/where/you/saved/the/extension/phars\"\n \u003e\n+    \u003cextensions\u003e\n+        \u003cextension class=\"TQ\\Testing\\Extension\\Stopwatch\\Extension\"/\u003e\n+    \u003c/extensions\u003e\n     \u003ctestsuites\u003e\n         \u003ctestsuite name=\"unit\"\u003e\n             \u003cdirectory\u003etest/Unit/\u003c/directory\u003e\n         \u003c/testsuite\u003e\n     \u003c/testsuites\u003e\n \u003c/phpunit\u003e\n```\n\n### Configuring the extension\n\nSo far, there are no configuration settings for this extension.\n\n### Running tests\n\nWhen you have bootstrapped the extension, you can run your tests as usually. E.g.:\n\n```sh\nvendor/bin/phpunit\n```\n\nWhen the extension is used somewhere in your code, it will give you a report:\n\n## License\n\nThis project uses the [MIT license](LICENSE.md).\n\n## Credits\n\nThis package is inspired by [`ergebnis/phpunit-slow-test-detector`](https://github.com/ergebnis/phpunit-slow-test-detector/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteqneers%2Fphpunit-stopwatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteqneers%2Fphpunit-stopwatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteqneers%2Fphpunit-stopwatch/lists"}