{"action":"created","issue":{"url":"https://api.github.com/repos/Seldaek/monolog/issues/542","labels_url":"https://api.github.com/repos/Seldaek/monolog/issues/542/labels{/name}","comments_url":"https://api.github.com/repos/Seldaek/monolog/issues/542/comments","events_url":"https://api.github.com/repos/Seldaek/monolog/issues/542/events","html_url":"https://github.com/Seldaek/monolog/pull/542","id":68614136,"number":542,"title":"Optimize replace new lines for LineFormatter","user":{"login":"ZhukV","id":2256109,"avatar_url":"https://avatars.githubusercontent.com/u/2256109?v=3","gravatar_id":"","url":"https://api.github.com/users/ZhukV","html_url":"https://github.com/ZhukV","followers_url":"https://api.github.com/users/ZhukV/followers","following_url":"https://api.github.com/users/ZhukV/following{/other_user}","gists_url":"https://api.github.com/users/ZhukV/gists{/gist_id}","starred_url":"https://api.github.com/users/ZhukV/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ZhukV/subscriptions","organizations_url":"https://api.github.com/users/ZhukV/orgs","repos_url":"https://api.github.com/users/ZhukV/repos","events_url":"https://api.github.com/users/ZhukV/events{/privacy}","received_events_url":"https://api.github.com/users/ZhukV/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-15T08:34:36Z","updated_at":"2015-04-15T18:23:07Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Seldaek/monolog/pulls/542","html_url":"https://github.com/Seldaek/monolog/pull/542","diff_url":"https://github.com/Seldaek/monolog/pull/542.diff","patch_url":"https://github.com/Seldaek/monolog/pull/542.patch"},"body":"After profile code with XHProf, i find a many uses for LineFormatter::replaceNewLines. After replace calls strtr to str_replace, called time is halved.\r\n\r\nWith use strtr: http://prntscr.com/6tycs1\r\nWith use str_replace: http://prntscr.com/6tycw8\r\n\r\nScript:\r\n\r\n```php\r\n$replaceTime = 0;\r\n$trTime = 0;\r\n\r\n$line = \"This is a testing line for benchmarking:\\nstrtr vs str_replace\\r\\nSecond line\\nThird line\";\r\n\r\nfor ($i = 0; $i < 10000; $i++) {\r\n    $time = microtime(true);\r\n    $newLine = str_replace([\"\\r\\n\", \"\\n\"], '', $line);\r\n    $replaceTime += microtime(true) - $time;\r\n\r\n    $time = microtime(true);\r\n    $newLine = strtr($line, [\"\\r\\n\" => ' ', \"\\n\" => ' ']);\r\n    $trTime += microtime(true) - $time;\r\n}\r\n\r\nprint sprintf(\r\n    \"Replace: %f\\nStrtr: %s\\n\",\r\n    $replaceTime,\r\n    $trTime\r\n);\r\n```\r\n\r\nThank."},"comment":{"url":"https://api.github.com/repos/Seldaek/monolog/issues/comments/93519914","html_url":"https://github.com/Seldaek/monolog/pull/542#issuecomment-93519914","issue_url":"https://api.github.com/repos/Seldaek/monolog/issues/542","id":93519914,"user":{"login":"Seldaek","id":183678,"avatar_url":"https://avatars.githubusercontent.com/u/183678?v=3","gravatar_id":"","url":"https://api.github.com/users/Seldaek","html_url":"https://github.com/Seldaek","followers_url":"https://api.github.com/users/Seldaek/followers","following_url":"https://api.github.com/users/Seldaek/following{/other_user}","gists_url":"https://api.github.com/users/Seldaek/gists{/gist_id}","starred_url":"https://api.github.com/users/Seldaek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Seldaek/subscriptions","organizations_url":"https://api.github.com/users/Seldaek/orgs","repos_url":"https://api.github.com/users/Seldaek/repos","events_url":"https://api.github.com/users/Seldaek/events{/privacy}","received_events_url":"https://api.github.com/users/Seldaek/received_events","type":"User","site_admin":false},"created_at":"2015-04-15T18:23:06Z","updated_at":"2015-04-15T18:23:06Z","body":"Interesting, this used to be the other way around I think, but anyway the benchmark checks out so let's do this. Thanks"}}