{"id":16288644,"url":"https://github.com/smuuf/phpcb","last_synced_at":"2025-03-20T03:30:41.642Z","repository":{"id":57054169,"uuid":"43033226","full_name":"smuuf/phpcb","owner":"smuuf","description":"A tiny benchmarking tool for PHP for true lovers of micro-optimization.","archived":false,"fork":false,"pushed_at":"2021-12-21T15:18:47.000Z","size":41,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-12T22:18:43.815Z","etag":null,"topics":["benchmark","performance","php","speed-benchmarking"],"latest_commit_sha":null,"homepage":"","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/smuuf.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":"2015-09-23T23:39:14.000Z","updated_at":"2025-01-29T19:32:32.000Z","dependencies_parsed_at":"2022-08-24T05:21:26.662Z","dependency_job_id":null,"html_url":"https://github.com/smuuf/phpcb","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smuuf%2Fphpcb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smuuf%2Fphpcb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smuuf%2Fphpcb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smuuf%2Fphpcb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smuuf","download_url":"https://codeload.github.com/smuuf/phpcb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244543716,"owners_count":20469550,"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":["benchmark","performance","php","speed-benchmarking"],"created_at":"2024-10-10T19:48:57.838Z","updated_at":"2025-03-20T03:30:41.158Z","avatar_url":"https://github.com/smuuf.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![PHP tests](https://github.com/smuuf/phpcb/actions/workflows/php.yml/badge.svg)](https://github.com/smuuf/phpcb/actions/workflows/php.yml)\n\n# phpcb (php code benchmark)\n\n**phpcb** is a very simple and very lightweight tool for speed benchmarking of various little pieces of PHP code, written in PHP, of course.\n\n### Why\n**phpcb** is meant to be used in those situations when there are multiple ways of how to do something - and you *know* all will have the exact same result - but you ***just can't*** decide which would ultimately be the best (meaning \"*fastest*\") to use.\n\n### Requirements\n- PHP 7.4+\n- *BCMath Arbitrary Precision Mathematics* library for PHP; shouldn't be a problem, since it is commonly shipped with PHP itself.\n\n### Installation\n```\ncomposer require --dev smuuf/-hpcb\n```\n\n### Usage\n\nWrite your microbenchmarks in a some file. For example `mymicrobench.php` _(here placed in phpcb's root directory, so it's clear we rquire Composer's autoload file from correct place)_:\n```php\n\u003c?php\n\nrequire __DIR__ . '/../vendor/autoload.php';\n$bench = new \\Smuuf\\Phpcb\\PhpBenchmark;\n\nconst COUNT = 100;\n\n$bench-\u003eaddBench(function() {\n\tfor ($i = 1; $i \u003c= COUNT; $i++) {}\n});\n\n$bench-\u003eaddBench(function() {\n\tfor ($i = COUNT; $i \u003e 0; $i--) {}\n});\n\n$bench-\u003eaddBench(function() {\n\tfor ($i = COUNT; $i--;) {}\n});\n\n$bench-\u003eaddBench(function() {\n\tfor ($i = -COUNT; $i++;) {}\n});\n\n$bench-\u003erun();\n```\n\nAnd then run it:\n```bash\n$ php ./mymicrobench.php\n```\n\nAnd observe results:\n\n```php\n█ PHP Code Benchmark (phpcb)\n█ PHP 7.4.27\n\nEngine used: Chaotic Engine\nTotal time: 1.3220 sec\nIterations: 1 000 000\n\n██ 2. Score: 100.00, 0.2660 sec\n┌\n│ $bench-\u003eaddBench(function() {\n│       for ($i = COUNT; $i \u003e 0; $i--) {}\n│ });\n└\n\n██ 1. Score: 86.54, 0.3074 sec, 1.16x slower\n┌\n│ $bench-\u003eaddBench(function() {\n│       for ($i = 1; $i \u003c= COUNT; $i++) {}\n│ });\n└\n\n██ 4. Score: 71.13, 0.3740 sec, 1.41x slower\n┌\n│ $bench-\u003eaddBench(function() {\n│       for ($i = -COUNT; $i++;) {}\n│ });\n└\n\n██ 3. Score: 71.02, 0.3746 sec, 1.41x slower\n┌\n│ $bench-\u003eaddBench(function() {\n│       for ($i = COUNT; $i--;) {}\n│ });\n└\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmuuf%2Fphpcb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmuuf%2Fphpcb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmuuf%2Fphpcb/lists"}