{"action":"created","comment":{"url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/pulls/comments/56761500","id":56761500,"diff_hunk":"@@ -0,0 +1,31 @@\n+require 'benchmark/ips'\n+\n+h = { a: { b: { c: { d: { e: \"foo\" } } } } }\n+\n+Benchmark.ips do |x|\n+  x.report 'Hash#dig' do\n+    h.dig(:a, :b, :c, :d, :e)\n+  end\n+\n+  x.report 'Hash#[]' do\n+    h[:a][:b][:c][:d][:e]\n+  end\n+\n+  x.report 'Hash#[] ||' do\n+    ((((h[:a] || {})[:b] || {})[:c] || {})[:d] || {})[:e]\n+  end\n+\n+  x.report 'Hash#[] &&' do\n+    h[:a] && h[:a][:b] && h[:a][:b][:c] && h[:a][:b][:c][:d] && h[:a][:b][:c][:d][:e]\n+  end\n+\n+  x.report 'Hash#fetch' do\n+    h.fetch(:a).fetch(:b).fetch(:c).fetch(:d).fetch(:e)\n+  end\n+\n+  x.report 'Hash#fetch fallback' do\n+    h.fetch(:a, {}).fetch(:b, {}).fetch(:c, {}).fetch(:d, {}).fetch(:e, nil)","path":"code/hash/dig-vs-[]-vs-fetch.rb","position":27,"original_position":27,"commit_id":"95b8ea491d5c4ab310c1166c2a280cd7f6356272","original_commit_id":"95b8ea491d5c4ab310c1166c2a280cd7f6356272","user":{"login":"ixti","id":94782,"avatar_url":"https://avatars.githubusercontent.com/u/94782?v=3","gravatar_id":"","url":"https://api.github.com/users/ixti","html_url":"https://github.com/ixti","followers_url":"https://api.github.com/users/ixti/followers","following_url":"https://api.github.com/users/ixti/following{/other_user}","gists_url":"https://api.github.com/users/ixti/gists{/gist_id}","starred_url":"https://api.github.com/users/ixti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ixti/subscriptions","organizations_url":"https://api.github.com/users/ixti/orgs","repos_url":"https://api.github.com/users/ixti/repos","events_url":"https://api.github.com/users/ixti/events{/privacy}","received_events_url":"https://api.github.com/users/ixti/received_events","type":"User","site_admin":false},"body":"@mblumtritt in fact it will not. Why would it create Proc?\r\n\r\nIn any case, @dideler I tend to agree that probably some people use `fetch(key, {})`.\r\nAnd that looks pretty fine, but in this case it worth to \"cache\" that object:\r\n\r\n``` ruby\r\no = {}\r\nh.fetch(:a, o).fetch(:b, o)\r\n```\r\n\r\nThat's just my thoughts. I don't insist on anything :D","created_at":"2016-03-20T09:31:12Z","updated_at":"2016-03-20T09:31:12Z","html_url":"https://github.com/JuanitoFatas/fast-ruby/pull/102#discussion_r56761500","pull_request_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/pulls/102","_links":{"self":{"href":"https://api.github.com/repos/JuanitoFatas/fast-ruby/pulls/comments/56761500"},"html":{"href":"https://github.com/JuanitoFatas/fast-ruby/pull/102#discussion_r56761500"},"pull_request":{"href":"https://api.github.com/repos/JuanitoFatas/fast-ruby/pulls/102"}}},"pull_request":{"url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/pulls/102","id":63313964,"html_url":"https://github.com/JuanitoFatas/fast-ruby/pull/102","diff_url":"https://github.com/JuanitoFatas/fast-ruby/pull/102.diff","patch_url":"https://github.com/JuanitoFatas/fast-ruby/pull/102.patch","issue_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/issues/102","number":102,"state":"open","locked":false,"title":"Add benchmark for Hash#dig vs #[] vs #fetch","user":{"login":"dideler","id":497458,"avatar_url":"https://avatars.githubusercontent.com/u/497458?v=3","gravatar_id":"","url":"https://api.github.com/users/dideler","html_url":"https://github.com/dideler","followers_url":"https://api.github.com/users/dideler/followers","following_url":"https://api.github.com/users/dideler/following{/other_user}","gists_url":"https://api.github.com/users/dideler/gists{/gist_id}","starred_url":"https://api.github.com/users/dideler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dideler/subscriptions","organizations_url":"https://api.github.com/users/dideler/orgs","repos_url":"https://api.github.com/users/dideler/repos","events_url":"https://api.github.com/users/dideler/events{/privacy}","received_events_url":"https://api.github.com/users/dideler/received_events","type":"User","site_admin":false},"body":"Comparison of how Ruby 2.3.0's `Hash#dig` performs to similar methods.\r\n\r\nUnsafe retrieval options are included. I can remove them if you consider them noisy.","created_at":"2016-03-18T00:44:08Z","updated_at":"2016-03-20T09:31:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b48e5a8cb4668204ec213c2117dc6d8781b8bbdf","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/pulls/102/commits","review_comments_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/pulls/102/comments","review_comment_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/pulls/comments{/number}","comments_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/issues/102/comments","statuses_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/statuses/95b8ea491d5c4ab310c1166c2a280cd7f6356272","head":{"label":"dideler:hash-dig-vs-index-fetch","ref":"hash-dig-vs-index-fetch","sha":"95b8ea491d5c4ab310c1166c2a280cd7f6356272","user":{"login":"dideler","id":497458,"avatar_url":"https://avatars.githubusercontent.com/u/497458?v=3","gravatar_id":"","url":"https://api.github.com/users/dideler","html_url":"https://github.com/dideler","followers_url":"https://api.github.com/users/dideler/followers","following_url":"https://api.github.com/users/dideler/following{/other_user}","gists_url":"https://api.github.com/users/dideler/gists{/gist_id}","starred_url":"https://api.github.com/users/dideler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dideler/subscriptions","organizations_url":"https://api.github.com/users/dideler/orgs","repos_url":"https://api.github.com/users/dideler/repos","events_url":"https://api.github.com/users/dideler/events{/privacy}","received_events_url":"https://api.github.com/users/dideler/received_events","type":"User","site_admin":false},"repo":{"id":54160096,"name":"fast-ruby","full_name":"dideler/fast-ruby","owner":{"login":"dideler","id":497458,"avatar_url":"https://avatars.githubusercontent.com/u/497458?v=3","gravatar_id":"","url":"https://api.github.com/users/dideler","html_url":"https://github.com/dideler","followers_url":"https://api.github.com/users/dideler/followers","following_url":"https://api.github.com/users/dideler/following{/other_user}","gists_url":"https://api.github.com/users/dideler/gists{/gist_id}","starred_url":"https://api.github.com/users/dideler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dideler/subscriptions","organizations_url":"https://api.github.com/users/dideler/orgs","repos_url":"https://api.github.com/users/dideler/repos","events_url":"https://api.github.com/users/dideler/events{/privacy}","received_events_url":"https://api.github.com/users/dideler/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dideler/fast-ruby","description":":dash: Writing Fast Ruby :heart_eyes: —— Collect Common Ruby idioms.","fork":true,"url":"https://api.github.com/repos/dideler/fast-ruby","forks_url":"https://api.github.com/repos/dideler/fast-ruby/forks","keys_url":"https://api.github.com/repos/dideler/fast-ruby/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dideler/fast-ruby/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dideler/fast-ruby/teams","hooks_url":"https://api.github.com/repos/dideler/fast-ruby/hooks","issue_events_url":"https://api.github.com/repos/dideler/fast-ruby/issues/events{/number}","events_url":"https://api.github.com/repos/dideler/fast-ruby/events","assignees_url":"https://api.github.com/repos/dideler/fast-ruby/assignees{/user}","branches_url":"https://api.github.com/repos/dideler/fast-ruby/branches{/branch}","tags_url":"https://api.github.com/repos/dideler/fast-ruby/tags","blobs_url":"https://api.github.com/repos/dideler/fast-ruby/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dideler/fast-ruby/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dideler/fast-ruby/git/refs{/sha}","trees_url":"https://api.github.com/repos/dideler/fast-ruby/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dideler/fast-ruby/statuses/{sha}","languages_url":"https://api.github.com/repos/dideler/fast-ruby/languages","stargazers_url":"https://api.github.com/repos/dideler/fast-ruby/stargazers","contributors_url":"https://api.github.com/repos/dideler/fast-ruby/contributors","subscribers_url":"https://api.github.com/repos/dideler/fast-ruby/subscribers","subscription_url":"https://api.github.com/repos/dideler/fast-ruby/subscription","commits_url":"https://api.github.com/repos/dideler/fast-ruby/commits{/sha}","git_commits_url":"https://api.github.com/repos/dideler/fast-ruby/git/commits{/sha}","comments_url":"https://api.github.com/repos/dideler/fast-ruby/comments{/number}","issue_comment_url":"https://api.github.com/repos/dideler/fast-ruby/issues/comments{/number}","contents_url":"https://api.github.com/repos/dideler/fast-ruby/contents/{+path}","compare_url":"https://api.github.com/repos/dideler/fast-ruby/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dideler/fast-ruby/merges","archive_url":"https://api.github.com/repos/dideler/fast-ruby/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dideler/fast-ruby/downloads","issues_url":"https://api.github.com/repos/dideler/fast-ruby/issues{/number}","pulls_url":"https://api.github.com/repos/dideler/fast-ruby/pulls{/number}","milestones_url":"https://api.github.com/repos/dideler/fast-ruby/milestones{/number}","notifications_url":"https://api.github.com/repos/dideler/fast-ruby/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dideler/fast-ruby/labels{/name}","releases_url":"https://api.github.com/repos/dideler/fast-ruby/releases{/id}","deployments_url":"https://api.github.com/repos/dideler/fast-ruby/deployments","created_at":"2016-03-18T00:17:09Z","updated_at":"2016-03-18T00:17:10Z","pushed_at":"2016-03-18T17:56:03Z","git_url":"git://github.com/dideler/fast-ruby.git","ssh_url":"git@github.com:dideler/fast-ruby.git","clone_url":"https://github.com/dideler/fast-ruby.git","svn_url":"https://github.com/dideler/fast-ruby","homepage":"https://github.com/JuanitoFatas/fast-ruby","size":1215,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"JuanitoFatas:master","ref":"master","sha":"ca29eedcdc55c7fa6af00e70fbb58cdd6f6c7bea","user":{"login":"JuanitoFatas","id":1000669,"avatar_url":"https://avatars.githubusercontent.com/u/1000669?v=3","gravatar_id":"","url":"https://api.github.com/users/JuanitoFatas","html_url":"https://github.com/JuanitoFatas","followers_url":"https://api.github.com/users/JuanitoFatas/followers","following_url":"https://api.github.com/users/JuanitoFatas/following{/other_user}","gists_url":"https://api.github.com/users/JuanitoFatas/gists{/gist_id}","starred_url":"https://api.github.com/users/JuanitoFatas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JuanitoFatas/subscriptions","organizations_url":"https://api.github.com/users/JuanitoFatas/orgs","repos_url":"https://api.github.com/users/JuanitoFatas/repos","events_url":"https://api.github.com/users/JuanitoFatas/events{/privacy}","received_events_url":"https://api.github.com/users/JuanitoFatas/received_events","type":"User","site_admin":false},"repo":{"id":25155580,"name":"fast-ruby","full_name":"JuanitoFatas/fast-ruby","owner":{"login":"JuanitoFatas","id":1000669,"avatar_url":"https://avatars.githubusercontent.com/u/1000669?v=3","gravatar_id":"","url":"https://api.github.com/users/JuanitoFatas","html_url":"https://github.com/JuanitoFatas","followers_url":"https://api.github.com/users/JuanitoFatas/followers","following_url":"https://api.github.com/users/JuanitoFatas/following{/other_user}","gists_url":"https://api.github.com/users/JuanitoFatas/gists{/gist_id}","starred_url":"https://api.github.com/users/JuanitoFatas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JuanitoFatas/subscriptions","organizations_url":"https://api.github.com/users/JuanitoFatas/orgs","repos_url":"https://api.github.com/users/JuanitoFatas/repos","events_url":"https://api.github.com/users/JuanitoFatas/events{/privacy}","received_events_url":"https://api.github.com/users/JuanitoFatas/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/JuanitoFatas/fast-ruby","description":":dash: Writing Fast Ruby :heart_eyes: —— Collect Common Ruby idioms.","fork":false,"url":"https://api.github.com/repos/JuanitoFatas/fast-ruby","forks_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/forks","keys_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/teams","hooks_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/hooks","issue_events_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/issues/events{/number}","events_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/events","assignees_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/assignees{/user}","branches_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/branches{/branch}","tags_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/tags","blobs_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/git/refs{/sha}","trees_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/statuses/{sha}","languages_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/languages","stargazers_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/stargazers","contributors_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/contributors","subscribers_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/subscribers","subscription_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/subscription","commits_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/commits{/sha}","git_commits_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/git/commits{/sha}","comments_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/comments{/number}","issue_comment_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/issues/comments{/number}","contents_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/contents/{+path}","compare_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/merges","archive_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/downloads","issues_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/issues{/number}","pulls_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/pulls{/number}","milestones_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/milestones{/number}","notifications_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/labels{/name}","releases_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/releases{/id}","deployments_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/deployments","created_at":"2014-10-13T11:19:28Z","updated_at":"2016-03-19T20:16:59Z","pushed_at":"2016-03-18T17:56:03Z","git_url":"git://github.com/JuanitoFatas/fast-ruby.git","ssh_url":"git@github.com:JuanitoFatas/fast-ruby.git","clone_url":"https://github.com/JuanitoFatas/fast-ruby.git","svn_url":"https://github.com/JuanitoFatas/fast-ruby","homepage":"https://github.com/JuanitoFatas/fast-ruby","size":1249,"stargazers_count":3041,"watchers_count":3041,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":178,"mirror_url":null,"open_issues_count":32,"forks":178,"open_issues":32,"watchers":3041,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/JuanitoFatas/fast-ruby/pulls/102"},"html":{"href":"https://github.com/JuanitoFatas/fast-ruby/pull/102"},"issue":{"href":"https://api.github.com/repos/JuanitoFatas/fast-ruby/issues/102"},"comments":{"href":"https://api.github.com/repos/JuanitoFatas/fast-ruby/issues/102/comments"},"review_comments":{"href":"https://api.github.com/repos/JuanitoFatas/fast-ruby/pulls/102/comments"},"review_comment":{"href":"https://api.github.com/repos/JuanitoFatas/fast-ruby/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/JuanitoFatas/fast-ruby/pulls/102/commits"},"statuses":{"href":"https://api.github.com/repos/JuanitoFatas/fast-ruby/statuses/95b8ea491d5c4ab310c1166c2a280cd7f6356272"}}}}