{"id":24795102,"url":"https://github.com/jamesgober/benchmark","last_synced_at":"2026-02-17T12:36:17.536Z","repository":{"id":274390853,"uuid":"922730559","full_name":"jamesgober/Benchmark","owner":"jamesgober","description":"PHP Benchmark library designed to measure code performance and memory usage with precision and efficiency.","archived":false,"fork":false,"pushed_at":"2025-03-18T18:20:53.000Z","size":59,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-21T09:44:02.250Z","etag":null,"topics":["benchmark","benchmarking","execution-time","memory-usage","php","php-benchmark","profiler"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jamesgober.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-01-26T23:57:31.000Z","updated_at":"2025-03-18T18:20:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"b2e89df5-b882-453e-9245-0761cc4290b1","html_url":"https://github.com/jamesgober/Benchmark","commit_stats":null,"previous_names":["jamesgober/benchmark"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/jamesgober/Benchmark","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesgober%2FBenchmark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesgober%2FBenchmark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesgober%2FBenchmark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesgober%2FBenchmark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamesgober","download_url":"https://codeload.github.com/jamesgober/Benchmark/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesgober%2FBenchmark/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29543908,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T12:21:34.159Z","status":"ssl_error","status_checked_at":"2026-02-17T12:21:02.057Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["benchmark","benchmarking","execution-time","memory-usage","php","php-benchmark","profiler"],"created_at":"2025-01-29T23:28:36.472Z","updated_at":"2026-02-17T12:36:12.521Z","avatar_url":"https://github.com/jamesgober.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 id=\"top\" align=\"center\"\u003e\n    \u003cpicture\u003e\n        \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"./docs/media/jamesgober-logo-dark.png\"\u003e\n        \u003cimg width=\"72\" height=\"72\" alt=\"Official brand mark and logo of James Gober. Image shows JG stylish initials encased in a hexagon outline.\" src=\"./docs/media/jamesgober-logo.png\"\u003e\n    \u003c/picture\u003e\n    \u003cbr\u003e\n    \u003cb\u003eBENCHMARK\u003c/b\u003e\n    \u003cbr\u003e\n    \u003csup\u003e\n        \u003csmall\u003e\u003csmall\u003e\u003csmall\u003e\n        PHP PERFORMANCE INSIGHTS\n        \u003c/small\u003e\u003c/small\u003e\u003c/small\u003e\n    \u003c/sup\u003e\n    \u003cbr\u003e\n\u003c/h1\u003e\n\n\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/stars/jamesgober/Benchmark?style=flat\" alt=\"GitHub Stars\"\u003e \u0026nbsp; \n    \u003cimg src=\"https://img.shields.io/github/issues/jamesgober/Benchmark?style=flat\" alt=\"GitHub Issues\"\u003e \u0026nbsp;  \n    \u003cimg src=\"https://img.shields.io/github/v/release/jamesgober/Benchmark?display_name=tag\u0026style=flat\" alt=\"GitHub Release\"\u003e \u0026nbsp; \n    \u003cimg src=\"https://img.shields.io/github/license/jamesgober/Benchmark?style=flat\" alt=\"GitHub License\"\u003e \u0026nbsp;\n    \u003cimg src=\"https://img.shields.io/badge/PHP-8.2-blue?style=flat\" alt=\"PHP Version\"\u003e \u0026nbsp;\n    \u003ca href=\"https://packagist.org/packages/jamesgober/Benchmark\" target=\"_blank\"\u003e\n        \u003cimg alt=\"Packagist Downloads\" src=\"https://img.shields.io/packagist/dt/jamesgober/Benchmark?style=flat\u0026color=%23f26f1a\"\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\n\u0026nbsp;\n\nBenchmark is a high-performance PHP library for measuring execution time and memory usage of code. Designed with precision, fault tolerance, and extensibility in mind, it provides advanced features like middleware hooks, configurable options, and detailed reporting to help developers optimize their applications.\n\n\u0026nbsp;\n\n## Key Features\n- **High-Resolution Timing**: Nanosecond-level precision using `hrtime`.\n- **Memory Tracking**: Track memory usage and peak memory consumption.\n- **Middleware Support**: Pre- and post-processing hooks for advanced customization.\n- **Grouped Benchmarking**: Run and analyze multiple benchmarks simultaneously.\n- **Statistical Analysis**: Generate averages, variances, and detailed reports over multiple iterations.\n- **Configurable Options**: Toggle features like verbose output and peak memory tracking.\n- **Integration Ready**: Export reports in JSON, array, or human-readable formats.\n- **Lightweight and Efficient**: Minimal overhead to keep performance at its peak.\n\n\u0026nbsp;\n\n\n## Installation\n\nInstall via [composer](https://getcomposer.org/download/):\n\n```sh\ncomposer \"require jamesgober/benchmark\"\n```\n\n\n\u0026nbsp;\n\n## Usage\n\n### Basic Benchmark\n\n```php\nuse JG\\Benchmark\\Benchmark;\n\n$benchmark = new Benchmark();\n\n$benchmark-\u003estart('example');\n// Code to benchmark\nusleep(1000); // Simulate a short delay\n$benchmark-\u003estop('example');\n\n// Get results\necho $benchmark-\u003egetTime('example'); // Outputs elapsed time\necho $benchmark-\u003egetMemory('example'); // Outputs memory usage\n```\n\n### Grouped Benchmark Report\n\n```php\n$benchmark-\u003estart('task1');\nusleep(2000);\n$benchmark-\u003estop('task1');\n\n$benchmark-\u003estart('task2');\nusleep(1000);\n$benchmark-\u003estop('task2');\n\nprint_r($benchmark-\u003egetReport());\n```\n\n#### Example Output\n\n```\nArray\n(\n    [task1] =\u003e Array\n        (\n            [time] =\u003e 0.002 ms\n            [memory] =\u003e 1.23 KB\n            [peak_memory] =\u003e 1.45 KB\n        )\n\n    [task2] =\u003e Array\n        (\n            [time] =\u003e 0.001 ms\n            [memory] =\u003e 1.12 KB\n            [peak_memory] =\u003e 1.32 KB\n        )\n)\n```\n\n### Middleware Example\n\n```php\n$benchmark-\u003eaddMiddleware('before', function ($name, $data) {\n    echo \"Starting benchmark: $name\\n\";\n});\n\n$benchmark-\u003eaddMiddleware('after', function ($name, $data) {\n    echo \"Finished benchmark: $name\\n\";\n});\n\n$benchmark-\u003estart('middleware_example');\nusleep(1500);\n$benchmark-\u003estop('middleware_example');\n```\n\n---\n\n\u0026nbsp;\n\n## Configuration\n\nCustomize behavior by passing an array of options to the constructor:\n\n```php\n$config = [\n    'track_peak_memory' =\u003e true,\n    'verbose' =\u003e false,\n];\n\n$benchmark = new Benchmark($config);\n```\n\n| Option              | Default | Description                        |\n|---------------------|---------|------------------------------------|\n| `track_peak_memory` | `true`  | Tracks peak memory usage if true.  |\n| `verbose`           | `false` | Enables verbose output if true.    |\n\n---\n\n\u0026nbsp;\n\n## Testing\n\nRun PHPUnit tests:\n\n```bash\ncomposer test\n```\n\nRun static analysis with PHPStan:\n\n```bash\ncomposer phpstan\n```\n\nRun both tests and static analysis:\n\n```bash\ncomposer check\n```\n---\n\n\u0026nbsp;\n\n## Reporting Bugs and Feature Requests\n\nFor bugs, feature requests, or security issues, please visit our **[Issue Tracker](https://github.com/jamesgober/Benchmark/issues)**.\n\nIf you discover a vulnerability, refer to our [Security Policy](.github/SECURITY.md).\n\n\u0026nbsp;\n\n## Contributing\n\nContributions are welcome! Please follow our [Contribution Guidelines](.github/CONTRIBUTING.md):\n\n1. Fork the repository.\n2. Create a feature branch.\n3. Commit your changes with descriptive messages.\n4. Open a pull request.\n\nEnsure all tests pass and adhere to the project's coding standards.\n\n\u0026nbsp;\n\n## License\nThis library is licensed under the [Apache-2.0](LICENSE) License.\n\n\n\u0026nbsp;\n\n---\n\n\u0026nbsp;\n\n\u003c!--\n####################################################\nCOPYRIGHT\n####################################################--\u003e\n\u003cdiv align=\"center\"\u003e\n    \u003ch2\u003e\u003c/h2\u003e\n    \u003csup\u003e\n        COPYRIGHT \u003csmall\u003e\u0026copy;\u003c/small\u003e 2025 \u003cstrong\u003eJAMES GOBER.\u003c/strong\u003e\n    \u003c/sup\u003e\n\u003c/div\u003e\n\n\u0026nbsp;\n\n\n\u003c!--\n####################################################\nLINKS\n####################################################--\u003e\n[Contribution Guidelines]: .github/CONTRIBUTING.md\n[CONTRIBUTING]:            .github/CONTRIBUTING.md\n[CODE OF CONDUCT]:         .github/CODE_OF_CONDUCT.md\n[REPORT SECURITY ISSUES]:  .github/SECURITY.md\n[SECURITY POLICY]:         .github/SECURITY.md\n[SECURITY]:                .github/SECURITY.md","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesgober%2Fbenchmark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamesgober%2Fbenchmark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesgober%2Fbenchmark/lists"}