{"action":"created","issue":{"url":"https://api.github.com/repos/composer/composer/issues/7214","repository_url":"https://api.github.com/repos/composer/composer","labels_url":"https://api.github.com/repos/composer/composer/issues/7214/labels{/name}","comments_url":"https://api.github.com/repos/composer/composer/issues/7214/comments","events_url":"https://api.github.com/repos/composer/composer/issues/7214/events","html_url":"https://github.com/composer/composer/issues/7214","id":308319365,"number":7214,"title":"why autoloader with optimization is slower than without optimization?","user":{"login":"cwhsu1984","id":1912413,"avatar_url":"https://avatars1.githubusercontent.com/u/1912413?v=4","gravatar_id":"","url":"https://api.github.com/users/cwhsu1984","html_url":"https://github.com/cwhsu1984","followers_url":"https://api.github.com/users/cwhsu1984/followers","following_url":"https://api.github.com/users/cwhsu1984/following{/other_user}","gists_url":"https://api.github.com/users/cwhsu1984/gists{/gist_id}","starred_url":"https://api.github.com/users/cwhsu1984/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cwhsu1984/subscriptions","organizations_url":"https://api.github.com/users/cwhsu1984/orgs","repos_url":"https://api.github.com/users/cwhsu1984/repos","events_url":"https://api.github.com/users/cwhsu1984/events{/privacy}","received_events_url":"https://api.github.com/users/cwhsu1984/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-25T03:38:49Z","updated_at":"2018-03-26T07:55:48Z","closed_at":"2018-03-26T05:57:30Z","author_association":"NONE","body":"I use composer 1.6.3.\r\n\r\nMy `composer.json`:\r\n\r\n```json\r\n{                                                                                                                                                                                                            \r\n    \"require\": {\r\n        \"php-di/php-di\": \"5.4.3\",\r\n        \"nesbot/carbon\": \"1.22.1\",\r\n        \"monolog/monolog\": \"1.22.1\"\r\n    },  \r\n    \"minimum-stability\": \"stable\"\r\n}\r\n```\r\n\r\nOutput of `composer diagnose`:\r\n\r\n```\r\nChecking composer.json: FAIL   // due to name and description i guess, I can download packages without issue\r\nNo license specified, it is recommended to do so. For closed-source software you may use \"proprietary\" as license.\r\nChecking platform settings: OK\r\nChecking git settings: OK\r\nChecking http connectivity to packagist: OK\r\nChecking https connectivity to packagist: OK\r\nChecking github.com oauth access: OK\r\nChecking disk free space: OK\r\n```\r\n\r\nWhen I run this command:\r\n\r\n```\r\ncomposer dumpautoload -o\r\n```\r\n\r\nI get the following output:\r\n\r\n```\r\nGenerating optimized autoload files\r\n```\r\n\r\nI expect that with dumpautoload -o the script should be faster than the one without it, but the result is not.\r\n\r\nThe script that use autoload:\r\n```\r\n<?php\r\n\r\n$x = microtime(true);\r\ninclude __DIR__.'/vendor/autoload.php';\r\n\r\nuse Monolog\\Logger;\r\nuse Monolog\\Handler\\StreamHandler;\r\n\r\n// create a log channel\r\n$log = new Logger('name');\r\n$log->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING));\r\n\r\n// add records to the log\r\n$log->warning('Foo');\r\n$log->error('Bar');\r\necho (microtime(true) - $x).\"\\n\";\r\n```\r\n\r\nThe script that runs the above script for some iterations:\r\n```\r\n<?php\r\n\r\n$i = 300;\r\n$x = 0;\r\nwhile ($i--) {\r\n    $x += (float) shell_exec(\"php a.php\");\r\n}\r\necho $x/300.0;\r\n```\r\nSo I run both version 300 times on my laptop, and the results are:\r\nwithout optimization: 0.0042489123344421\r\nwith optimization (-o): 0.0044415553410848\r\nwith optimization (-a): 0.0045802394549052\r\n\r\nSo why the one with optimization is slower?"},"comment":{"url":"https://api.github.com/repos/composer/composer/issues/comments/376077854","html_url":"https://github.com/composer/composer/issues/7214#issuecomment-376077854","issue_url":"https://api.github.com/repos/composer/composer/issues/7214","id":376077854,"user":{"login":"cwhsu1984","id":1912413,"avatar_url":"https://avatars1.githubusercontent.com/u/1912413?v=4","gravatar_id":"","url":"https://api.github.com/users/cwhsu1984","html_url":"https://github.com/cwhsu1984","followers_url":"https://api.github.com/users/cwhsu1984/followers","following_url":"https://api.github.com/users/cwhsu1984/following{/other_user}","gists_url":"https://api.github.com/users/cwhsu1984/gists{/gist_id}","starred_url":"https://api.github.com/users/cwhsu1984/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cwhsu1984/subscriptions","organizations_url":"https://api.github.com/users/cwhsu1984/orgs","repos_url":"https://api.github.com/users/cwhsu1984/repos","events_url":"https://api.github.com/users/cwhsu1984/events{/privacy}","received_events_url":"https://api.github.com/users/cwhsu1984/received_events","type":"User","site_admin":false},"created_at":"2018-03-26T07:55:48Z","updated_at":"2018-03-26T07:55:48Z","author_association":"NONE","body":"@alcohol\r\nCould you kindly give me a brief explanation? Did I do something wrong or misunderstanding something?"}}
{"actor":{"display_login":"cwhsu1984"}}