{"id":32957567,"url":"https://github.com/mre/PHPench","last_synced_at":"2025-11-16T19:01:27.254Z","repository":{"id":19698357,"uuid":"22953173","full_name":"mre/PHPench","owner":"mre","description":"Realtime benchmarks for PHP code","archived":false,"fork":false,"pushed_at":"2019-10-21T13:16:18.000Z","size":405,"stargazers_count":53,"open_issues_count":3,"forks_count":4,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-08-01T23:59:57.187Z","etag":null,"topics":["algorithms","benchmark","comparison","framework","gnuplot","php","profiling","realtime","realtime-metrics"],"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/mre.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-14T12:38:53.000Z","updated_at":"2022-12-10T16:53:07.000Z","dependencies_parsed_at":"2022-08-05T05:00:33.129Z","dependency_job_id":null,"html_url":"https://github.com/mre/PHPench","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mre/PHPench","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mre%2FPHPench","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mre%2FPHPench/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mre%2FPHPench/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mre%2FPHPench/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mre","download_url":"https://codeload.github.com/mre/PHPench/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mre%2FPHPench/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284759739,"owners_count":27058842,"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-11-16T02:00:05.974Z","response_time":65,"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":["algorithms","benchmark","comparison","framework","gnuplot","php","profiling","realtime","realtime-metrics"],"created_at":"2025-11-12T23:00:25.276Z","updated_at":"2025-11-16T19:01:27.248Z","avatar_url":"https://github.com/mre.png","language":"PHP","readme":"# PHPench\n\n![A pretty graph](graph.gif)\n\nPHPench creates a graphical output for a PHP benchmark.\nPlot the runtime of any function in realtime with GnuPlot and create an image\nout of the result.\n\n[![Build Status](https://travis-ci.org/mre/PHPench.svg)](https://travis-ci.org/mre/PHPench)\n\n## Why is it useful?\n\n#### Algorithms are beautiful\n\nSometimes the difference between two algorithms is hard to explain but easy to show.  \nFor instance, take two sorting algorithms which both have a best-case\nruntime of `O(n*log n)`. Depending on the input, one can be much faster than the\nother. This tools helps you see what's going on.\n\n#### Death to premature-optimizations\n\nWhenever people tell you that using single quotes instead of double quotes\naround strings is a performance improvement, it's time to debunk some myths.\nMost of the time such programmer folklore turns out to be misguided and can actually be pretty harmful.  \n*\"Premature emphasis on efficiency is a big mistake which may well be the source\nof most programming complexity and grief.\"* (Donald Knuth)  \nLet's be professionals. Let's measure.\n\n## Example\n\nUsing PHPench feels a bit like writing a visual unit test. Check it out:  \n\n```PHP\n\u003c?php\n\nrequire_once __DIR__.'/../vendor/autoload.php';\n\n/*\n * You can use an closure or a class that implements TestInterface.\n *\n * Data that will be processed by the tested function can be executed\n * without including its execution time. This will provide more accurate data.\n */\n\nabstract class AbstractBenchmark implements \\mre\\PHPench\\BenchmarkInterface\n{\n    protected $test;\n\n    function setUp($arrSize)\n    {\n        $this-\u003etest = array();\n        for ($i=1; $i\u003c$arrSize; $i++) {\n            $this-\u003etest[$i]= $arrSize % $i;\n        }\n\n        return $this-\u003etest;\n    }\n}\n\nclass BenchmarkArrayFlip extends AbstractBenchmark\n{\n    public function execute() {\n        $test = array_flip(array_flip($this-\u003etest));\n    }\n}\n\nclass BenchmarkArrayUnique extends AbstractBenchmark\n{\n    public function execute() {\n        $test = array_unique($this-\u003etest);\n    }\n}\n\n// Create a new benchmark instance\n$phpench = new \\mre\\PHPench(new \\mre\\PHPench\\Aggregator\\MedianAggregator);\n\n// Use GnuPlot for output\n$oOutput = new \\mre\\PHPench\\Output\\GnuPlotOutput('test2.png', 1024, 768);\n\n// Alternatively, print the values to the terminal\n//$oOutput = new \\mre\\PHPench\\Output\\CliOutput();\n\n$oOutput-\u003esetTitle('Compare array_flip and array_unique');\n$phpench-\u003esetOutput($oOutput);\n\n// Add your test to the instance\n$phpench-\u003eaddBenchmark(new BenchmarkArrayFlip, 'array_flip');\n$phpench-\u003eaddBenchmark(new BenchmarkArrayUnique, 'array_unique');\n\n// Run the benchmark and plot the results in realtime.\n// With the second parameter you can specify\n// the start, end and step for each call\n$phpench-\u003esetInput(range(1,pow(2,16), 1024));\n$phpench-\u003esetRepetitions(4);\n$phpench-\u003erun();\n```\n\n## Installation\n\n1.) Add this package to your composer.json\n\n```\n{\n    \"require\": {\n      \"mre/phpench\": \"*@dev\"\n    }\n}\n```\n\n2.) Install gnuplot (Version 4.6)\n\nFor *Mac OS X* you can install gnuplot via homebrew. For live generated charts you also need to install XQuartz.\n```\nWithout X11 support:\n$ brew install homebrew/versions/gnuplot4\n\nWith X11 supprt (recommended!):\n$ brew install homebrew/versions/gnuplot4 --with-x11\n```\n\nFor *Linux* use your package manager.\n```\napt-get install gnuplot\n```\n\n3.) Look at the examples for usage\n\n## Maintainers\n\nMatthias Endler (@matthiasendler)  \nMarkus Poerschke (@markuspoerschke)\n\n## License\n\nApache License Version 2.0\n","funding_links":[],"categories":["Benchmark - PHP"],"sub_categories":["Meetups"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmre%2FPHPench","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmre%2FPHPench","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmre%2FPHPench/lists"}