{"id":19275945,"url":"https://github.com/nsa-yoda/phpbenchtime","last_synced_at":"2026-02-01T22:00:53.440Z","repository":{"id":5537960,"uuid":"6741371","full_name":"nsa-yoda/PHPBenchTime","owner":"nsa-yoda","description":"A lightweight benchmark timer for PHP","archived":false,"fork":false,"pushed_at":"2022-12-03T22:55:14.000Z","size":194,"stargazers_count":25,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-01T21:30:50.182Z","etag":null,"topics":["lap","php","timer"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nsa-yoda.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-11-17T23:26:49.000Z","updated_at":"2024-04-09T08:59:03.000Z","dependencies_parsed_at":"2023-01-13T13:35:28.452Z","dependency_job_id":null,"html_url":"https://github.com/nsa-yoda/PHPBenchTime","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/nsa-yoda/PHPBenchTime","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsa-yoda%2FPHPBenchTime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsa-yoda%2FPHPBenchTime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsa-yoda%2FPHPBenchTime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsa-yoda%2FPHPBenchTime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nsa-yoda","download_url":"https://codeload.github.com/nsa-yoda/PHPBenchTime/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsa-yoda%2FPHPBenchTime/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28992629,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T20:57:35.821Z","status":"ssl_error","status_checked_at":"2026-02-01T20:57:29.580Z","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":["lap","php","timer"],"created_at":"2024-11-09T20:52:26.514Z","updated_at":"2026-02-01T22:00:53.434Z","avatar_url":"https://github.com/nsa-yoda.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHPBenchTime v3.0.0\n\n[![CI](https://github.com/nsa-yoda/PHPBenchTime/actions/workflows/ci.yml/badge.svg)](https://github.com/nsa-yoda/PHPBenchTime/actions/workflows/ci.yml)\n[![Total Downloads](https://poser.pugx.org/jsanc623/phpbenchtime/downloads)](https://packagist.org/packages/jsanc623/phpbenchtime)\n[![Monthly Downloads](https://poser.pugx.org/jsanc623/phpbenchtime/d/monthly)](https://packagist.org/packages/jsanc623/phpbenchtime)\n[![License](https://poser.pugx.org/jsanc623/phpbenchtime/license)](https://packagist.org/packages/jsanc623/phpbenchtime)\n[![Dependabot Updates](https://github.com/nsa-yoda/PHPBenchTime/actions/workflows/dependabot/dependabot-updates/badge.svg)](https://github.com/nsa-yoda/PHPBenchTime/actions/workflows/dependabot/dependabot-updates)\n[![pages-build-deployment](https://github.com/nsa-yoda/PHPBenchTime/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/nsa-yoda/PHPBenchTime/actions/workflows/pages/pages-build-deployment)\n\nA lightweight benchmark timer for PHP with laps, pause/unpause support, and a simple summary output.  \nDesigned for clarity, correctness, and minimal overhead.\n\n\u003e **PHPBenchTime v3.0 requires PHP 8.1+** (enum-backed state, typed properties, private internals).\n\nIf you’re interested, there is also a Python implementation:  \n👉 **PyBenchTime** — https://github.com/nsa-yoda/PyBenchTime\n\n---\n\n## Installation\n\nInstall via Composer:\n\n```bash\ncomposer require nsa-yoda/phpbenchtime\n```\n\nAutoloading is handled automatically.\n\n## Quick Start\n\n```php \n\u003c?php\n\nrequire __DIR__ . '/vendor/autoload.php';\n\nuse PHPBenchTime\\Timer;\n\n$t = new Timer();\n$t-\u003estart();\nsleep(1);\n$t-\u003eend();\n\nprint_r($t-\u003esummary());\n?\u003e\n```\n\n## Core Concepts\n\n- Timers are stateful and controlled via methods only\n- All internal properties are private\n- State is represented by a PHP 8.1 enum\n- All timings are floats (seconds, from microtime(true))\n- summary() returns a read-only snapshot\n\n## Public API\n\n### Methods\n\n```php\nstart(string $name = \"start\"): void\nend(): void\nreset(): void\nlap(?string $name = null): void\nsummary(): array\npause(): void\nunpause(): void\n```\n\n### Read-only Getters\n\n```php\ngetState(): TimerState\ngetStartTime(): float\ngetEndTime(): float\ngetPauseTime(): float\ngetTotalPauseTime(): float\ngetLaps(): array\ngetLapCount(): int\n```\n\n## Basic Usage\n\n```php\n$t = new Timer();\n$t-\u003estart();\n\nsleep(3);\n\n$t-\u003eend();\n\nprint_r($t-\u003esummary());\n```\n\n### Example Output\n\n```php\nArray\n(\n    [running] =\u003e -1\n    [start]   =\u003e 1706812345.1234\n    [end]     =\u003e 1706812348.1239\n    [total]   =\u003e 3.0005\n    [paused]  =\u003e 0\n    [laps]    =\u003e Array\n        (\n            [0] =\u003e Array\n                (\n                    [name]  =\u003e start\n                    [start] =\u003e 1706812345.1234\n                    [end]   =\u003e 1706812348.1239\n                    [total] =\u003e 3.0005\n                )\n        )\n)\n```\n\nrunning is the enum value:\n1 = RUNNING, 0 = PAUSED, -1 = STOPPED\n\n### Laps\n\nLaps allow you to isolate portions of execution time.\nEach call to lap() automatically closes the previous lap.\n\n```php\n$t = new Timer();\n$t-\u003estart();\n\nsleep(1);\n$t-\u003elap();\n\nsleep(2);\n$t-\u003elap();\n\n$t-\u003eend();\n```\n\n### Named Laps\n\nFor clearer output, provide names to start() and lap():\n\n```php\n$t = new Timer();\n$t-\u003estart('bootstrap');\n\nsleep(1);\n$t-\u003elap('database');\n\nsleep(1);\n$t-\u003elap('render');\n\n$t-\u003eend();\n```\n\n### Pause \u0026 Unpause\n\nPaused time is excluded from total runtime but still tracked.\n\n```php\n$t = new Timer();\n$t-\u003estart();\n\nsleep(1);\n$t-\u003elap('before pause');\n\n$t-\u003epause();\nsleep(3); // excluded from total\n$t-\u003eunpause();\n\nsleep(1);\n$t-\u003elap('after pause');\n\n$t-\u003eend();\n```\n\nPaused duration is available via:\n\n```php\n$t-\u003egetTotalPauseTime();\n```\n\nCalling end() while paused will automatically finalize the pause.\n\n## Documentation\n\nA richer usage guide (with examples and explanations) is available in: `docs/index.html`\n\nThis file can be found on th rpojrects GitHub Pages: https://nsa-yoda.github.io/PHPBenchTime/\n\n## History\n\n- v3.0.0 - Changes to tighten up the codebase for PHP8.1, strongly typed, and enums etc\n- v2.1.0 - Performance improvements, unit tests, PHP 8.1 modernization\n- v2.0.0 - Complete rewrite: pause/unpause, centralized lap system, detailed summary\n- v1.3.0 - Laps, laps, laps\n- v1.2.0 - Non-static namespaces\n- v1.1.0 - Static namespaces\n- v1.0.0 - Static birth\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnsa-yoda%2Fphpbenchtime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnsa-yoda%2Fphpbenchtime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnsa-yoda%2Fphpbenchtime/lists"}