{"id":15077755,"url":"https://github.com/hoaproject/contributions-symfony-benchbundle","last_synced_at":"2025-10-05T11:31:50.805Z","repository":{"id":19949470,"uuid":"23216255","full_name":"hoaproject/Contributions-Symfony-BenchBundle","owner":"hoaproject","description":"The Hoa\\Bench Symfony2 bundle.","archived":true,"fork":false,"pushed_at":"2014-11-09T10:08:04.000Z","size":358,"stargazers_count":2,"open_issues_count":3,"forks_count":1,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-09-20T18:47:19.225Z","etag":null,"topics":[],"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/hoaproject.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":"2014-08-22T07:07:01.000Z","updated_at":"2023-01-28T06:27:30.000Z","dependencies_parsed_at":"2022-08-17T15:55:20.809Z","dependency_job_id":null,"html_url":"https://github.com/hoaproject/Contributions-Symfony-BenchBundle","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hoaproject/Contributions-Symfony-BenchBundle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FContributions-Symfony-BenchBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FContributions-Symfony-BenchBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FContributions-Symfony-BenchBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FContributions-Symfony-BenchBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hoaproject","download_url":"https://codeload.github.com/hoaproject/Contributions-Symfony-BenchBundle/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FContributions-Symfony-BenchBundle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278445915,"owners_count":25988076,"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","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-09-25T04:31:44.874Z","updated_at":"2025-10-05T11:31:50.416Z","avatar_url":"https://github.com/hoaproject.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Hoa](http://static.hoa-project.net/Image/Hoa_small.png)\n\nHoa is a **modular**, **extensible** and **structured** set of PHP libraries.\nMoreover, Hoa aims at being a bridge between industrial and research worlds.\n\n# Hoathis\\BenchBundle [![Build Status](https://travis-ci.org/jubianchi/HoathisBenchBundle.png?branch=master)](https://travis-ci.org/jubianchi/HoathisBenchBundle)\n\n* [Installation](#installation)\n* [How to use](#how-to-use)\n * [Bench service](#bench-service)\n * [Twig helper](#twig-helper)\n * [Console helper](#console-helper)\n\n## Installation\n\nAdd these lines to your `require-dev` section:\n\n```json\n{\n    \"require-dev\": {\n        \"hoa/core\": \"*@dev\",\n        \"hoa/bench\": \"*@dev\",\n        \"hoathis/bench-bundle\": \"dev-master\"\n    }\n}\n```\n\nThen install dependencies:\n\n```sh\n$ composer update hoathis/bench-bundle\n```\n\nAnd add `BenchBundle` to your `AppKernel`:\n\n```php\n//app/AppKernel.php\n\nclass AppKernel extends Kernel\n{\n    …\n\n    public function registerBundles()\n    {\n        if (in_array($this-\u003egetEnvironment(), array('dev', 'test'))) {\n            …\n            $bundles[] = new \\Hoathis\\Bundle\\BenchBundle\\BenchBundle();\n        }\n\n        return $bundles;\n    }\n}\n```\n\n## How to use\n\n### Bench service\n\n`BenchBundle` will automatically setup a `bench` service which you can use in\nyour PHP code to benchmark parts of your application. Results will be aggregated\nand reported in the profile.\n\n```php\n\u003c?php\n\nnamespace Hoathis\\BenchDemoBundle\\Controller;\n\nuse Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller;\n\nclass DemoController extends Controller\n{\n    public function indexAction()\n    {\n        $this-\u003econtainer-\u003eget('bench')-\u003erenderView-\u003estart();\n        $response = $this-\u003erender('HoaDemoBundle:Welcome:index.html.twig');\n        $this-\u003econtainer-\u003eget('bench')-\u003erenderView-\u003estop();\n\n        return $response;\n    }\n}\n```\n\nIn the previous example we created a mark named `renderView` in measuring the\ntime taken to render the Twig template.\n\nYou can create several marks by simply assigning them a unique name and nest\nthem as you want:\n\n```php\npublic function indexAction()\n{\n    $this-\u003econtainer-\u003eget('bench')-\u003efetchUsers-\u003estart();\n    $users = …\n    \n    foreach($users as $user) {\n        $this-\u003econtainer-\u003eget('bench')-\u003efetchMessages-\u003estart();\n        $user-\u003emessages = …\n        $this-\u003econtainer-\u003eget('bench')-\u003efetchMessages-\u003epause();\n    }\n    \n    $this-\u003econtainer-\u003eget('bench')-\u003efetchMessages-\u003estop(true);\n    $this-\u003econtainer-\u003eget('bench')-\u003efetchUsers-\u003estop();\n\n    $this-\u003econtainer-\u003eget('bench')-\u003erenderView-\u003estart();\n    $response = $this-\u003erender('HoaDemoBundle:Users:index.html.twig', array('users' =\u003e $users));\n    $this-\u003econtainer-\u003eget('bench')-\u003erenderView-\u003estop();\n\n    return $response;\n}\n```\n\nAs you can see in the previous example you have three methods to control mark\nstate:\n\n* `Hoa\\Bench\\Mark::start()`: to start or unpause a mark,\n* `Hoa\\Bench\\Mark::pause($silent = false)`: to pause a mark,\n* `Hoa\\Bench\\Mark::stop($silent = false)`: to stop a mark.\n\nYou can also get more informations from marks using their [native\nAPI](http://hoa-project.net/Literature/Hack/Bench.html#Manipulate_marks).\n\n### Twig helper\n\n`BenchBundle` also adds a Twig helper to use marks inside your templates:\n\n```html\n\u003cul\u003e\n    {% benchstart 'usersLoop' %}\n    {% for user in users %}\n        \u003cli\u003e\n            {{ user.username }}\n\n            {% benchstart 'messagesCount' %}\n            \u003cspan\u003e\n                {% if user.messages|length %}\n                    No new mesages\n                {% else %}\n                   {{ user.messages|length }} new message(s)\n                {% endif %}\n            \u003c/span\u003e\n            {% benchpause 'messagesCount' %}\n        \u003cli\u003e\n    {% endfor %}\n    {% benchstop 'messagesCount' %}\n    {% benchstop 'usersLoop' %}\n\u003cul\u003e\n```\n\nResults of those marks will also be displayed in the web profiler.\n\n### Console helper\n\nFinally, `BenchBundle` will configure a `bench.helper` service which you can use\nin your console commands to access marks:\n\n```php\n\u003c?php\nnamespace Hoa\\DemoBundle\\Command;\n\nuse Symfony\\Bundle\\FrameworkBundle\\Command\\ContainerAwareCommand;\nuse Symfony\\Component\\Console\\Input\\InputInterface;\nuse Symfony\\Component\\Console\\Output\\OutputInterface;\n\nclass TestCommand extends ContainerAwareCommand\n{\n    public function __construct($name = null)\n    {\n        parent::__construct($name ?: 'hoa:bench:demo');\n    }\n\n    protected function execute(InputInterface $input, OutputInterface $output)\n    {\n        $bench = $this-\u003egetContainer()-\u003eget('bench.helper');\n\n        $bench-\u003estart('foo');\n        …\n\n        $bench-\u003estart('bar');\n        …\n        $bench-\u003estop('bar');\n\n        $bench-\u003estop('foo');\n\n        $bench-\u003esummarize($output);\n    }\n} \n```\n\nThe API is the same as the `bench` service except that with the helper, you pass\nmarks' names as argument of the `start`/`pause`/`stop` methods.\n\nThe results will be render on the command's output when you call the\n`summarize`method:\n\n```sh\n$ app/console hoa:bench:demo\n# ...\n+------+-----------------+-----------------+\n| Mark | Time            | Percent         |\n+------+-----------------+-----------------+\n| foo  | 4.0034830570221 | 100             |\n| bar  | 2.001620054245  | 49.996965785434 |\n+------+-----------------+-----------------+\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoaproject%2Fcontributions-symfony-benchbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhoaproject%2Fcontributions-symfony-benchbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoaproject%2Fcontributions-symfony-benchbundle/lists"}