GitHub PullRequestEvent at 2014-10-19 21:23:43
Repository: rails
Actor: rafaelfranca
Payload: {"action":"closed","number":17316,"pull_request":{"url":"https://api.github.com/repos/rails/rails/pulls/17316","id":22979248,"html_url":"https://github.com/rails/rails/pull/17316","diff_url":"https://github.com/rails/rails/pull/17316.diff","patch_url":"https://github.com/rails/rails/pull/17316.patch","issue_url":"https://api.github.com/repos/rails/rails/issues/17316","number":17316,"state":"closed","locked":false,"title":"Replace checking start/end of string","user":{"login":"igas","id":175652,"avatar_url":"https://avatars.githubusercontent.com/u/175652?v=2","gravatar_id":"","url":"https://api.github.com/users/igas","html_url":"https://github.com/igas","followers_url":"https://api.github.com/users/igas/followers","following_url":"https://api.github.com/users/igas/following{/other_user}","gists_url":"https://api.github.com/users/igas/gists{/gist_id}","starred_url":"https://api.github.com/users/igas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/igas/subscriptions","organizations_url":"https://api.github.com/users/igas/orgs","repos_url":"https://api.github.com/users/igas/repos","events_url":"https://api.github.com/users/igas/events{/privacy}","received_events_url":"https://api.github.com/users/igas/received_events","type":"User","site_admin":false},"body":"Replace `=~ /^str/`, `=~ /str$/`, `!~ /^str/`, and `!~ /str$/` to `start_with?` and `end_with?` when possible. Mostly it's 1,6x faster, some more impressive benchmarks:\r\n\r\n**actionpack/lib/abstract_controller/helpers.rb**:\r\n\r\n```ruby\r\nBenchmark.ips do |x|\r\n  x.report('=~') { error.path =~ /^#{path}(\\.rb)?$/ }\r\n  x.report('start/end') { error.path.start_with?(path) && error.path.end_with?('.rb', '') }\r\n  x.compare!\r\nend\r\n```\r\n\r\n```\r\nCalculating -------------------------------------\r\n                  =~      7097 i/100ms\r\n           start/end     29688 i/100ms\r\n-------------------------------------------------\r\n                  =~   104752.3 (±8.3%) i/s -     525178 in   5.049548s\r\n           start/end  2423935.7 (±10.8%) i/s -   11964264 in   5.003489s\r\n\r\nComparison:\r\n           start/end:  2423935.7 i/s\r\n                  =~:   104752.3 i/s - 23.14x slower\r\n```\r\n\r\n--\r\n\r\n**actionpack/lib/action_dispatch/journey/visitors.rb**:\r\n\r\n```ruby\r\nBenchmark.ips do |x|\r\n  x.report('=~') do\r\n    next unless pim =~ /^visit_(.*)$/\r\n    DISPATCH_CACHE[$1.to_sym] = pim\r\n  end\r\n  x.report('start/end') do\r\n    next unless pim.to_s.start_with?('visit_')\r\n    DISPATCH_CACHE[pim[/^visit_(.*)$/, 1].to_sym] = pim\r\n  end\r\n  x.compare!\r\nend\r\n```\r\n\r\n```\r\nCalculating -------------------------------------\r\n                  =~     58993 i/100ms\r\n           start/end     73946 i/100ms\r\n-------------------------------------------------\r\n                  =~  1832025.8 (±6.6%) i/s -    9143915 in   5.012602s\r\n           start/end  2944646.4 (±8.2%) i/s -   14641308 in   5.006457s\r\n\r\nComparison:\r\n           start/end:  2944646.4 i/s\r\n                  =~:  1832025.8 i/s - 1.61x slower\r\n```\r\n\r\n--\r\n\r\n**actionview/lib/action_view/helpers/asset_tag_helper.rb**:\r\n\r\n```ruby\r\nBenchmark.ips do |x|\r\n  x.report('=~') { src =~ /^(?:cid|data):/ }\r\n  x.report('start/end') { src.start_with?('cid:', 'data:') }\r\n  x.compare!\r\nend\r\n```\r\n\r\n```\r\nCalculating -------------------------------------\r\n                  =~     26869 i/100ms\r\n           start/end     29965 i/100ms\r\n-------------------------------------------------\r\n                  =~  1853626.9 (±8.5%) i/s -    9189198 in   4.996903s\r\n           start/end  2894114.5 (±13.0%) i/s -   14173445 in   4.993368s\r\n\r\nComparison:\r\n           start/end:  2894114.5 i/s\r\n                  =~:  1853626.9 i/s - 1.56x slower\r\n```\r\n\r\n--\r\n\r\n**actionview/lib/action_view/renderer/template_renderer.rb**:\r\n\r\n```ruby\r\nBenchmark.ips do |x|\r\n  x.report('=~') { layout =~ /^\\// }\r\n  x.report('start/end') { layout.start_with?('/') }\r\n  x.compare!\r\nend\r\n```\r\n\r\n```\r\nCalculating -------------------------------------\r\n                  =~     25597 i/100ms\r\n           start/end     33362 i/100ms\r\n-------------------------------------------------\r\n                  =~  1451851.0 (±9.4%) i/s -    7192757 in   5.000724s\r\n           start/end  4360476.8 (±14.0%) i/s -   21251594 in   4.996049s\r\n\r\nComparison:\r\n           start/end:  4360476.8 i/s\r\n                  =~:  1451851.0 i/s - 3.00x slower\r\n```\r\n\r\n--\r\n\r\n**activesupport/lib/active_support/multibyte/chars.rb**:\r\n\r\n```ruby\r\nBenchmark.ips do |x|\r\n  x.report('=~') { method.to_s =~ /!$/ }\r\n  x.report('start/end') { method.to_s.end_with?('!') }\r\n  x.compare!\r\nend\r\n```\r\n\r\n```\r\nCalculating -------------------------------------\r\n                  =~     25899 i/100ms\r\n           start/end     30125 i/100ms\r\n-------------------------------------------------\r\n                  =~  2046233.9 (±9.2%) i/s -   10126509 in   4.998104s\r\n           start/end  3313337.1 (±12.0%) i/s -   16267500 in   4.994593s\r\n\r\nComparison:\r\n           start/end:  3313337.1 i/s\r\n                  =~:  2046233.9 i/s - 1.62x slower\r\n```","created_at":"2014-10-19T10:53:18Z","updated_at":"2014-10-19T21:23:41Z","closed_at":"2014-10-19T21:23:41Z","merged_at":null,"merge_commit_sha":"f57b8155076c816558c720e6e4e1fe072592accc","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rails/rails/pulls/17316/commits","review_comments_url":"https://api.github.com/repos/rails/rails/pulls/17316/comments","review_comment_url":"https://api.github.com/repos/rails/rails/pulls/comments/{number}","comments_url":"https://api.github.com/repos/rails/rails/issues/17316/comments","statuses_url":"https://api.github.com/repos/rails/rails/statuses/ceef709495a48ce413cf1238be6f1dfdee06c937","head":{"label":"igas:fast-ruby-start_with","ref":"fast-ruby-start_with","sha":"ceef709495a48ce413cf1238be6f1dfdee06c937","user":{"login":"igas","id":175652,"avatar_url":"https://avatars.githubusercontent.com/u/175652?v=2","gravatar_id":"","url":"https://api.github.com/users/igas","html_url":"https://github.com/igas","followers_url":"https://api.github.com/users/igas/followers","following_url":"https://api.github.com/users/igas/following{/other_user}","gists_url":"https://api.github.com/users/igas/gists{/gist_id}","starred_url":"https://api.github.com/users/igas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/igas/subscriptions","organizations_url":"https://api.github.com/users/igas/orgs","repos_url":"https://api.github.com/users/igas/repos","events_url":"https://api.github.com/users/igas/events{/privacy}","received_events_url":"https://api.github.com/users/igas/received_events","type":"User","site_admin":false},"repo":{"id":24965271,"name":"rails","full_name":"igas/rails","owner":{"login":"igas","id":175652,"avatar_url":"https://avatars.githubusercontent.com/u/175652?v=2","gravatar_id":"","url":"https://api.github.com/users/igas","html_url":"https://github.com/igas","followers_url":"https://api.github.com/users/igas/followers","following_url":"https://api.github.com/users/igas/following{/other_user}","gists_url":"https://api.github.com/users/igas/gists{/gist_id}","starred_url":"https://api.github.com/users/igas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/igas/subscriptions","organizations_url":"https://api.github.com/users/igas/orgs","repos_url":"https://api.github.com/users/igas/repos","events_url":"https://api.github.com/users/igas/events{/privacy}","received_events_url":"https://api.github.com/users/igas/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/igas/rails","description":"Ruby on Rails","fork":true,"url":"https://api.github.com/repos/igas/rails","forks_url":"https://api.github.com/repos/igas/rails/forks","keys_url":"https://api.github.com/repos/igas/rails/keys{/key_id}","collaborators_url":"https://api.github.com/repos/igas/rails/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/igas/rails/teams","hooks_url":"https://api.github.com/repos/igas/rails/hooks","issue_events_url":"https://api.github.com/repos/igas/rails/issues/events{/number}","events_url":"https://api.github.com/repos/igas/rails/events","assignees_url":"https://api.github.com/repos/igas/rails/assignees{/user}","branches_url":"https://api.github.com/repos/igas/rails/branches{/branch}","tags_url":"https://api.github.com/repos/igas/rails/tags","blobs_url":"https://api.github.com/repos/igas/rails/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/igas/rails/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/igas/rails/git/refs{/sha}","trees_url":"https://api.github.com/repos/igas/rails/git/trees{/sha}","statuses_url":"https://api.github.com/repos/igas/rails/statuses/{sha}","languages_url":"https://api.github.com/repos/igas/rails/languages","stargazers_url":"https://api.github.com/repos/igas/rails/stargazers","contributors_url":"https://api.github.com/repos/igas/rails/contributors","subscribers_url":"https://api.github.com/repos/igas/rails/subscribers","subscription_url":"https://api.github.com/repos/igas/rails/subscription","commits_url":"https://api.github.com/repos/igas/rails/commits{/sha}","git_commits_url":"https://api.github.com/repos/igas/rails/git/commits{/sha}","comments_url":"https://api.github.com/repos/igas/rails/comments{/number}","issue_comment_url":"https://api.github.com/repos/igas/rails/issues/comments/{number}","contents_url":"https://api.github.com/repos/igas/rails/contents/{+path}","compare_url":"https://api.github.com/repos/igas/rails/compare/{base}...{head}","merges_url":"https://api.github.com/repos/igas/rails/merges","archive_url":"https://api.github.com/repos/igas/rails/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/igas/rails/downloads","issues_url":"https://api.github.com/repos/igas/rails/issues{/number}","pulls_url":"https://api.github.com/repos/igas/rails/pulls{/number}","milestones_url":"https://api.github.com/repos/igas/rails/milestones{/number}","notifications_url":"https://api.github.com/repos/igas/rails/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/igas/rails/labels{/name}","releases_url":"https://api.github.com/repos/igas/rails/releases{/id}","created_at":"2014-10-08T23:23:54Z","updated_at":"2014-10-08T20:04:09Z","pushed_at":"2014-10-19T12:57:12Z","git_url":"git://github.com/igas/rails.git","ssh_url":"git@github.com:igas/rails.git","clone_url":"https://github.com/igas/rails.git","svn_url":"https://github.com/igas/rails","homepage":"http://rubyonrails.org","size":120633,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rails:master","ref":"master","sha":"9bbff50cc272862305593cc0d5f930f688e5955f","user":{"login":"rails","id":4223,"avatar_url":"https://avatars.githubusercontent.com/u/4223?v=2","gravatar_id":"","url":"https://api.github.com/users/rails","html_url":"https://github.com/rails","followers_url":"https://api.github.com/users/rails/followers","following_url":"https://api.github.com/users/rails/following{/other_user}","gists_url":"https://api.github.com/users/rails/gists{/gist_id}","starred_url":"https://api.github.com/users/rails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails/subscriptions","organizations_url":"https://api.github.com/users/rails/orgs","repos_url":"https://api.github.com/users/rails/repos","events_url":"https://api.github.com/users/rails/events{/privacy}","received_events_url":"https://api.github.com/users/rails/received_events","type":"Organization","site_admin":false},"repo":{"id":8514,"name":"rails","full_name":"rails/rails","owner":{"login":"rails","id":4223,"avatar_url":"https://avatars.githubusercontent.com/u/4223?v=2","gravatar_id":"","url":"https://api.github.com/users/rails","html_url":"https://github.com/rails","followers_url":"https://api.github.com/users/rails/followers","following_url":"https://api.github.com/users/rails/following{/other_user}","gists_url":"https://api.github.com/users/rails/gists{/gist_id}","starred_url":"https://api.github.com/users/rails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails/subscriptions","organizations_url":"https://api.github.com/users/rails/orgs","repos_url":"https://api.github.com/users/rails/repos","events_url":"https://api.github.com/users/rails/events{/privacy}","received_events_url":"https://api.github.com/users/rails/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rails/rails","description":"Ruby on Rails","fork":false,"url":"https://api.github.com/repos/rails/rails","forks_url":"https://api.github.com/repos/rails/rails/forks","keys_url":"https://api.github.com/repos/rails/rails/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rails/rails/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rails/rails/teams","hooks_url":"https://api.github.com/repos/rails/rails/hooks","issue_events_url":"https://api.github.com/repos/rails/rails/issues/events{/number}","events_url":"https://api.github.com/repos/rails/rails/events","assignees_url":"https://api.github.com/repos/rails/rails/assignees{/user}","branches_url":"https://api.github.com/repos/rails/rails/branches{/branch}","tags_url":"https://api.github.com/repos/rails/rails/tags","blobs_url":"https://api.github.com/repos/rails/rails/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rails/rails/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rails/rails/git/refs{/sha}","trees_url":"https://api.github.com/repos/rails/rails/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rails/rails/statuses/{sha}","languages_url":"https://api.github.com/repos/rails/rails/languages","stargazers_url":"https://api.github.com/repos/rails/rails/stargazers","contributors_url":"https://api.github.com/repos/rails/rails/contributors","subscribers_url":"https://api.github.com/repos/rails/rails/subscribers","subscription_url":"https://api.github.com/repos/rails/rails/subscription","commits_url":"https://api.github.com/repos/rails/rails/commits{/sha}","git_commits_url":"https://api.github.com/repos/rails/rails/git/commits{/sha}","comments_url":"https://api.github.com/repos/rails/rails/comments{/number}","issue_comment_url":"https://api.github.com/repos/rails/rails/issues/comments/{number}","contents_url":"https://api.github.com/repos/rails/rails/contents/{+path}","compare_url":"https://api.github.com/repos/rails/rails/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rails/rails/merges","archive_url":"https://api.github.com/repos/rails/rails/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rails/rails/downloads","issues_url":"https://api.github.com/repos/rails/rails/issues{/number}","pulls_url":"https://api.github.com/repos/rails/rails/pulls{/number}","milestones_url":"https://api.github.com/repos/rails/rails/milestones{/number}","notifications_url":"https://api.github.com/repos/rails/rails/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rails/rails/labels{/name}","releases_url":"https://api.github.com/repos/rails/rails/releases{/id}","created_at":"2008-04-11T02:19:47Z","updated_at":"2014-10-19T18:12:34Z","pushed_at":"2014-10-19T18:09:33Z","git_url":"git://github.com/rails/rails.git","ssh_url":"git@github.com:rails/rails.git","clone_url":"https://github.com/rails/rails.git","svn_url":"https://github.com/rails/rails","homepage":"http://rubyonrails.org","size":394563,"stargazers_count":23545,"watchers_count":23545,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":8991,"mirror_url":null,"open_issues_count":755,"forks":8991,"open_issues":755,"watchers":23545,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rails/rails/pulls/17316"},"html":{"href":"https://github.com/rails/rails/pull/17316"},"issue":{"href":"https://api.github.com/repos/rails/rails/issues/17316"},"comments":{"href":"https://api.github.com/repos/rails/rails/issues/17316/comments"},"review_comments":{"href":"https://api.github.com/repos/rails/rails/pulls/17316/comments"},"review_comment":{"href":"https://api.github.com/repos/rails/rails/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/rails/rails/pulls/17316/commits"},"statuses":{"href":"https://api.github.com/repos/rails/rails/statuses/ceef709495a48ce413cf1238be6f1dfdee06c937"}},"merged":false,"mergeable":true,"mergeable_state":"clean","merged_by":null,"comments":2,"review_comments":5,"commits":1,"additions":33,"deletions":31,"changed_files":26}}