{"id":13483540,"url":"https://github.com/fastruby/fast-ruby","last_synced_at":"2025-10-15T23:12:34.181Z","repository":{"id":21832554,"uuid":"25155580","full_name":"fastruby/fast-ruby","owner":"fastruby","description":":dash: Writing Fast Ruby :heart_eyes: -- Collect Common Ruby idioms.","archived":false,"fork":false,"pushed_at":"2025-03-07T13:45:30.000Z","size":1386,"stargazers_count":5713,"open_issues_count":48,"forks_count":378,"subscribers_count":172,"default_branch":"main","last_synced_at":"2025-05-08T21:04:22.175Z","etag":null,"topics":["benchmark-ips","hacktoberfest","performance-optimization","ruby"],"latest_commit_sha":null,"homepage":"https://github.com/fastruby/fast-ruby","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fastruby.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-10-13T11:19:28.000Z","updated_at":"2025-05-08T03:51:32.000Z","dependencies_parsed_at":"2024-05-01T08:52:41.363Z","dependency_job_id":"64f2b3fa-820e-46ea-9b27-e8b3cafabbf3","html_url":"https://github.com/fastruby/fast-ruby","commit_stats":null,"previous_names":["juanitofatas/fast-ruby"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastruby%2Ffast-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastruby%2Ffast-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastruby%2Ffast-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastruby%2Ffast-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fastruby","download_url":"https://codeload.github.com/fastruby/fast-ruby/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254101559,"owners_count":22014908,"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","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":["benchmark-ips","hacktoberfest","performance-optimization","ruby"],"created_at":"2024-07-31T17:01:12.539Z","updated_at":"2025-10-15T23:12:34.115Z","avatar_url":"https://github.com/fastruby.png","language":"Ruby","funding_links":[],"categories":["Coding Style Guides","Ruby"],"sub_categories":[],"readme":"Fast Ruby [![Benchmarks](https://github.com/fastruby/fast-ruby/actions/workflows/benchmarks.yml/badge.svg)](https://github.com/fastruby/fast-ruby/actions/workflows/benchmarks.yml)\n=======================================================================================================================================================================\n\nIn [Erik Michaels-Ober](https://github.com/sferik)'s great talk, 'Writing Fast Ruby': [Video @ Baruco 2014](https://www.youtube.com/watch?v=fGFM_UrSp70), [Slide](https://speakerdeck.com/sferik/writing-fast-ruby), he presented us with many idioms that lead to faster running Ruby code. He inspired me to document these to let more people know. I try to link to real commits so people can see that this can really have benefits in the real world. **This does not mean you can always blindly replace one with another. It depends on the context (e.g. `gsub` versus `tr`). Friendly reminder: Use with caution!**\n\nEach idiom has a corresponding code example that resides in [code](code).\n\nAll results listed in README.md are running with Ruby 2.2.0p0 on OS X 10.10.1. Machine information: MacBook Pro (Retina, 15-inch, Mid 2014), 2.5 GHz Intel Core i7, 16 GB 1600 MHz DDR3. Your results may vary, but you get the idea. : )\n\nYou can checkout [the GitHub Actions build](https://github.com/fastruby/fast-ruby/actions) for these benchmark results ran against different Ruby implementations.\n\n**Let's write faster code, together! \u003c3**\n\nAnalyze your code\n-----------------\n\nCheckout the [fasterer](https://github.com/DamirSvrtan/fasterer) project - it's a static analysis that checks speed idioms written in this repo.\n\nMeasurement Tool\n-----------------\n\nUse [benchmark-ips](https://github.com/evanphx/benchmark-ips) (2.0+).\n\n### Template\n\n```ruby\nrequire \"benchmark/ips\"\n\ndef fast\nend\n\ndef slow\nend\n\nBenchmark.ips do |x|\n  x.report(\"fast code description\") { fast }\n  x.report(\"slow code description\") { slow }\n  x.compare!\nend\n```\n\nIdioms\n------\n\n### Index\n\n- [General](#general)\n- [Array](#array)\n- [Date](#date)\n- [Enumerable](#enumerable)\n- [Hash](#hash)\n- [Proc \u0026 Block](#proc--block)\n- [String](#string)\n- [Time](#time)\n- [Range](#range)\n\n### General\n\n##### `attr_accessor` vs `getter and setter` [code](code/general/attr-accessor-vs-getter-and-setter.rb)\n\n\u003e https://www.omniref.com/ruby/2.2.0/files/method.h?#annotation=4081781\u0026line=47\n\n```\n$ ruby -v code/general/attr-accessor-vs-getter-and-setter.rb\nruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]\nCalculating -------------------------------------\n   getter_and_setter    61.240k i/100ms\n       attr_accessor    66.535k i/100ms\n-------------------------------------------------\n   getter_and_setter      1.660M (± 9.7%) i/s -      8.267M\n       attr_accessor      1.865M (± 9.2%) i/s -      9.248M\n\nComparison:\n       attr_accessor:  1865408.4 i/s\n   getter_and_setter:  1660021.9 i/s - 1.12x slower\n```\n\n##### `begin...rescue` vs `respond_to?` for Control Flow [code](code/general/begin-rescue-vs-respond-to.rb)\n\n```\n$ ruby -v code/general/begin-rescue-vs-respond-to.rb\nruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]\n\nCalculating -------------------------------------\n      begin...rescue    29.452k i/100ms\n         respond_to?   106.528k i/100ms\n-------------------------------------------------\n      begin...rescue    371.591k (± 5.4%) i/s -      1.855M\n         respond_to?      3.277M (± 7.5%) i/s -     16.299M\n\nComparison:\n         respond_to?:  3276972.3 i/s\n      begin...rescue:   371591.0 i/s - 8.82x slower\n```\n\n##### `define_method` vs `module_eval` for Defining Methods [code](code/general/define_method-vs-module-eval.rb)\n\n```\n$ ruby -v code/general/define_method-vs-module-eval.rb\nruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]\n\nCalculating -------------------------------------\nmodule_eval with string 125.000  i/100ms\n       define_method    138.000  i/100ms\n-------------------------------------------------\nmodule_eval with string   1.130k (±20.3%) i/s -      5.500k\n       define_method      1.346k (±25.9%) i/s -      6.348k\n\nComparison:\n       define_method:        1345.6 i/s\nmodule_eval with string:     1129.7 i/s - 1.19x slower\n```\n\n##### `String#constantize` vs a comparison for inflection [code](code/general/constantize-vs-comparison.rb)\n\nActiveSupport's [String#constantize](https://guides.rubyonrails.org/active_support_core_extensions.html#constantize) \"resolves the constant reference expression in its receiver\".\n\n[Read the rationale here](https://github.com/fastruby/fast-ruby/pull/200)\n\n```\nruby 2.7.3p183 (2021-04-05 revision 6847ee089d) [x86_64-darwin20]\n\nCalculating -------------------------------------\nusing an if statement\n                          8.124M (± 1.8%) i/s -     41.357M in   5.092437s\n  String#constantize      2.462M (± 2.4%) i/s -     12.315M in   5.004089s\n\nComparison:\nusing an if statement:  8123851.3 i/s\n  String#constantize:  2462371.2 i/s - 3.30x  (± 0.00) slower\n```\n\n##### `raise` vs `E2MM#Raise` for raising (and defining) exceptions  [code](code/general/raise-vs-e2mmap.rb)\n\nRuby's [Exception2MessageMapper module](http://ruby-doc.org/stdlib-2.2.0/libdoc/e2mmap/rdoc/index.html) allows one to define and raise exceptions with predefined messages.\n\n```\n$ ruby -v code/general/raise-vs-e2mmap.rb\nruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]\n\nCalculating -------------------------------------\nRuby exception: E2MM#Raise\n                         2.865k i/100ms\nRuby exception: Kernel#raise\n                        42.215k i/100ms\n-------------------------------------------------\nRuby exception: E2MM#Raise\n                         27.270k (± 8.8%) i/s -    137.520k\nRuby exception: Kernel#raise\n                        617.446k (± 7.9%) i/s -      3.082M\n\nComparison:\nRuby exception: Kernel#raise:   617446.2 i/s\nRuby exception: E2MM#Raise:    27269.8 i/s - 22.64x slower\n\nCalculating -------------------------------------\nCustom exception: E2MM#Raise\n                         2.807k i/100ms\nCustom exception: Kernel#raise\n                        45.313k i/100ms\n-------------------------------------------------\nCustom exception: E2MM#Raise\n                         29.005k (± 7.2%) i/s -    145.964k\nCustom exception: Kernel#raise\n                        589.149k (± 7.8%) i/s -      2.945M\n\nComparison:\nCustom exception: Kernel#raise:   589148.7 i/s\nCustom exception: E2MM#Raise:    29004.8 i/s - 20.31x slower\n```\n\n##### `loop` vs `while true` [code](code/general/loop-vs-while-true.rb)\n\n```\n$ ruby -v code/general/loop-vs-while-true.rb\nruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]\n\nCalculating -------------------------------------\n          While Loop     1.000  i/100ms\n         Kernel loop     1.000  i/100ms\n-------------------------------------------------\n          While Loop      0.536  (± 0.0%) i/s -      3.000  in   5.593042s\n         Kernel loop      0.223  (± 0.0%) i/s -      2.000  in   8.982355s\n\nComparison:\n          While Loop:        0.5 i/s\n         Kernel loop:        0.2 i/s - 2.41x slower\n```\n\n##### `ancestors.include?` vs `\u003c=` [code](code/general/inheritance-check.rb)\n\n```\n$ ruby -vW0 code/general/inheritance-check.rb\nruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux]\nWarming up --------------------------------------\n  less than or equal    66.992k i/100ms\n  ancestors.include?    16.943k i/100ms\nCalculating -------------------------------------\n  less than or equal      1.250M (± 6.4%) i/s -      6.230M in   5.006896s\n  ancestors.include?    192.603k (± 4.8%) i/s -    965.751k in   5.025917s\n\nComparison:\n  less than or equal:  1249606.0 i/s\n  ancestors.include?:   192602.9 i/s - 6.49x  slower\n```\n\n### Method Invocation\n\n##### `call` vs `send` vs `method_missing` [code](code/method/call-vs-send-vs-method_missing.rb)\n\n```\n$ ruby -v code/method/call-vs-send-vs-method_missing.rb\nruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]\n\nCalculating -------------------------------------\n                call   115.094k i/100ms\n                send   105.258k i/100ms\n      method_missing   100.762k i/100ms\n-------------------------------------------------\n                call      3.811M (± 5.9%) i/s -     18.991M\n                send      3.244M (± 7.2%) i/s -     16.210M\n      method_missing      2.729M (± 9.8%) i/s -     13.401M\n\nComparison:\n                call:  3811183.4 i/s\n                send:  3244239.1 i/s - 1.17x slower\n      method_missing:  2728893.0 i/s - 1.40x slower\n```\n\n##### Normal way to apply method vs `\u0026method(...)` [code](code/general/block-apply-method.rb)\n\n```\n$ ruby -v code/general/block-apply-method.rb\nruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]\n\nCalculating -------------------------------------\n              normal    85.749k i/100ms\n             \u0026method    35.529k i/100ms\n-------------------------------------------------\n              normal      1.867M (± 7.6%) i/s -      9.347M\n             \u0026method    467.095k (± 6.4%) i/s -      2.345M\n\nComparison:\n              normal:  1866669.5 i/s\n             \u0026method:   467095.4 i/s - 4.00x slower\n```\n\n##### Function with single Array argument vs splat arguments [code](code/general/array-argument-vs-splat-arguments.rb)\n\n```\n$ ruby -v code/general/array-argument-vs-splat-arguments.rb\nruby 2.1.7p400 (2015-08-18 revision 51632) [x86_64-linux-gnu]\nCalculating -------------------------------------\nFunction with single Array argument\n                       157.231k i/100ms\nFunction with splat arguments\n                         4.983k i/100ms\n-------------------------------------------------\nFunction with single Array argument\n                          5.581M (± 2.0%) i/s -     27.987M\nFunction with splat arguments\n                         54.428k (± 3.3%) i/s -    274.065k\n\nComparison:\nFunction with single Array argument:  5580972.6 i/s\nFunction with splat arguments:    54427.7 i/s - 102.54x slower\n\n```\n\n##### Hash vs OpenStruct on access assuming you already have a Hash or an OpenStruct [code](code/general/hash-vs-openstruct-on-access.rb)\n\n```\n$ ruby -v code/general/hash-vs-openstruct-on-access.rb\nruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]\n\nCalculating -------------------------------------\n                Hash   128.344k i/100ms\n          OpenStruct   110.723k i/100ms\n-------------------------------------------------\n                Hash      5.279M (± 7.0%) i/s -     26.311M\n          OpenStruct      3.048M (± 7.0%) i/s -     15.169M\n\nComparison:\n                Hash:  5278844.0 i/s\n          OpenStruct:  3048139.8 i/s - 1.73x slower\n```\n\n##### Hash vs OpenStruct (creation) [code](code/general/hash-vs-openstruct.rb)\n\n```\n$ ruby -v code/general/hash-vs-openstruct.rb\nruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]\n\nCalculating -------------------------------------\n                Hash    75.510k i/100ms\n          OpenStruct     9.126k i/100ms\n-------------------------------------------------\n                Hash      1.604M (±11.0%) i/s -      7.929M\n          OpenStruct     96.855k (± 9.9%) i/s -    483.678k\n\nComparison:\n                Hash:  1604259.1 i/s\n          OpenStruct:    96855.3 i/s - 16.56x slower\n```\n\n##### Kernel#format vs Float#round().to_s [code](code/general/format-vs-round-and-to-s.rb)\n\n```\n$ ruby -v code/general/format-vs-round-and-to-s.rb\nruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin15]\nWarming up --------------------------------------\n         Float#round   106.645k i/100ms\n       Kernel#format    84.304k i/100ms\n            String#%    78.635k i/100ms\nCalculating -------------------------------------\n         Float#round      1.570M (± 3.2%) i/s - 7.892M in   5.030672s\n       Kernel#format      1.144M (± 3.0%) i/s - 5.733M in   5.015621s\n            String#%      1.047M (± 4.2%) i/s - 5.269M in   5.042970s\n\nComparison:\n         Float#round:  1570411.4 i/s\n       Kernel#format:  1144036.6 i/s - 1.37x  slower\n            String#%:  1046689.1 i/s - 1.50x  slower\n```\n\n### Array\n\n##### `Array#bsearch` vs `Array#find` [code](code/array/bsearch-vs-find.rb)\n\n**WARNING:** `bsearch` ONLY works on *sorted array*. More details please see [#29](https://github.com/fastruby/fast-ruby/issues/29).\n\n```\n$ ruby -v code/array/bsearch-vs-find.rb\nruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]\n\nCalculating -------------------------------------\n                find     1.000  i/100ms\n             bsearch    42.216k i/100ms\n-------------------------------------------------\n                find      0.184  (± 0.0%) i/s -      1.000  in   5.434758s\n             bsearch    577.301k (± 6.6%) i/s -      2.913M\n\nComparison:\n             bsearch:   577300.7 i/s\n                find:        0.2 i/s - 3137489.63x slower\n```\n\n##### `Array#length` vs `Array#size` vs `Array#count` [code](code/array/length-vs-size-vs-count.rb)\n\nUse `#length` when you only want to know how many elements in the array, `#count` could also achieve this. However `#count` should be use for counting specific elements in array. [Note `#size` is an alias of `#length`](https://github.com/ruby/ruby/blob/f8fb526ad9e9f31453bffbc908b6a986736e21a7/array.c#L5817-L5818).\n\n```\n$ ruby -v code/array/length-vs-size-vs-count.rb\nruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]\n\nCalculating -------------------------------------\n        Array#length   172.998k i/100ms\n          Array#size   168.130k i/100ms\n         Array#count   164.911k i/100ms\n-------------------------------------------------\n        Array#length     11.394M (± 6.1%) i/s -     56.743M\n          Array#size     11.303M (± 6.5%) i/s -     56.324M\n         Array#count      9.195M (± 8.6%) i/s -     45.680M\n\nComparison:\n        Array#length: 11394036.7 i/s\n          Array#size: 11302701.1 i/s - 1.01x slower\n         Array#count:  9194976.2 i/s - 1.24x slower\n```\n\n##### `Array#shuffle.first` vs `Array#sample` [code](code/array/shuffle-first-vs-sample.rb)\n\n\u003e `Array#shuffle` allocates an extra array. \u003cbr\u003e\n\u003e `Array#sample` indexes into the array without allocating an extra array. \u003cbr\u003e\n\u003e This is the reason why Array#sample exists. \u003cbr\u003e\n\u003e —— @sferik [rails/rails#17245](https://github.com/rails/rails/pull/17245)\n\n```\n$ ruby -v code/array/shuffle-first-vs-sample.rb\nruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]\n\nCalculating -------------------------------------\n Array#shuffle.first    25.406k i/100ms\n        Array#sample   125.101k i/100ms\n-------------------------------------------------\n Array#shuffle.first    304.341k (± 4.3%) i/s -      1.524M\n        Array#sample      5.727M (± 8.6%) i/s -     28.523M\n\nComparison:\n        Array#sample:  5727032.0 i/s\n Array#shuffle.first:   304341.1 i/s - 18.82x slower\n```\n\n##### `Array#[](0)` vs `Array#first` [code](code/array/array-first-vs-index.rb)\n\n```\n$ ruby -v code/array/array-first-vs-index.rb\nruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]\n\nCalculating -------------------------------------\n           Array#[0]   152.751k i/100ms\n         Array#first   148.088k i/100ms\n-------------------------------------------------\n           Array#[0]      8.614M (± 7.0%) i/s -     42.923M\n         Array#first      7.465M (±10.7%) i/s -     36.874M\n\nComparison:\n           Array#[0]:  8613583.7 i/s\n         Array#first:  7464526.6 i/s - 1.15x slower\n```\n\n##### `Array#[](-1)` vs `Array#last` [code](code/array/array-last-vs-index.rb)\n\n```\n$ ruby -v code/array/array-last-vs-index.rb\nruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]\n\nCalculating -------------------------------------\n            Array#[-1]   151.940k i/100ms\n          Array#last   153.371k i/100ms\n-------------------------------------------------\n            Array#[-1]      8.582M (± 4.6%) i/s -     42.847M\n          Array#last      7.639M (± 5.7%) i/s -     38.189M\n\nComparison:\n            Array#[-1]:  8582074.3 i/s\n          Array#last:  7639254.5 i/s - 1.12x slower\n```\n\n##### `Array#insert` vs `Array#unshift` [code](code/array/insert-vs-unshift.rb)\n\n```\n$ ruby -v code/array/insert-vs-unshift.rb\nruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin10.0]\nCalculating -------------------------------------\n       Array#unshift     4.000  i/100ms\n        Array#insert     1.000  i/100ms\n-------------------------------------------------\n       Array#unshift     44.947  (± 6.7%) i/s -    224.000\n        Array#insert      0.171  (± 0.0%) i/s -      1.000  in   5.841595s\n\nComparison:\n       Array#unshift:       44.9 i/s\n        Array#insert:        0.2 i/s - 262.56x slower\n\n```\n##### `Array#concat` vs `Array#+` [code](code/array/array-concat-vs-+.rb)\n`Array#+` returns a new array built by concatenating the two arrays together to\nproduce a third array. `Array#concat` appends the elements of the other array to self.\nThis means that the + operator will create a new array each time it is called\n(which is expensive), while concat only appends the new element.\n```\n$ ruby -v code/array/array-concat-vs-+.rb\nruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin18]\nWarming up --------------------------------------\n        Array#concat    23.000  i/100ms\n             Array#+     1.000  i/100ms\nCalculating -------------------------------------\n        Array#concat    217.669  (±15.2%) i/s -      1.058k in   5.016952s\n             Array#+      1.475  (± 0.0%) i/s -      8.000  in   5.467642s\n\nComparison:\n        Array#concat:      217.7 i/s\n             Array#+:        1.5 i/s - 147.54x  slower\n```\n\n##### `Array#new` vs `Fixnum#times + map` [code](code/array/array-new-vs-fixnum-times-map.rb)\n\nTypical slowdown is 40-60% depending on the size of the array. See the corresponding\n[pull request](https://github.com/fastruby/fast-ruby/pull/91/) for performance characteristics.\n\n```\nruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]\nCalculating -------------------------------------\n           Array#new    63.875k i/100ms\n  Fixnum#times + map    48.010k i/100ms\n-------------------------------------------------\n           Array#new      1.070M (± 2.2%) i/s -      5.365M\n  Fixnum#times + map    678.097k (± 2.7%) i/s -      3.409M\n\nComparison:\n           Array#new:  1069837.0 i/s\n  Fixnum#times + map:   678097.4 i/s - 1.58x slower\n```\n\n##### `Array#sort.reverse` vs `Array#sort_by` +  block [code](code/array/sort-reverse-vs-sort_by-with-block.rb)\n\n```\n$ ruby -v code/array/sort-reverse-vs-sort_by.rb\nruby 2.5.2p104 (2018-10-18 revision 65133) [x86_64-darwin13]\nWarming up --------------------------------------\nArray#sort.reverse\n                        16.231k i/100ms\nArray#sort_by \u0026:-@\n                         5.406k i/100ms\nCalculating -------------------------------------\nArray#sort.reverse\n                        149.492k (±11.0%) i/s -    746.626k in   5.070375s\nArray#sort_by \u0026:-@\n                         51.981k (± 8.8%) i/s -    259.488k in   5.041625s\n\nComparison:\nArray#sort.reverse:   149492.2 i/s\nArray#sort_by \u0026:-@:    51980.6 i/s - 2.88x  (± 0.00) slower\n```\n\n### Enumerable\n\n##### `Enumerable#each + push` vs `Enumerable#map` [code](code/enumerable/each-push-vs-map.rb)\n\n```\n$ ruby -v code/enumerable/each-push-vs-map.rb\nruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]\n\nCalculating -------------------------------------\n   Array#each + push     9.025k i/100ms\n           Array#map    13.947k i/100ms\n-------------------------------------------------\n   Array#each + push     99.634k (± 3.2%) i/s -    505.400k\n           Array#map    158.091k (± 4.2%) i/s -    794.979k\n\nComparison:\n           Array#map:   158090.9 i/s\n   Array#each + push:    99634.2 i/s - 1.59x slower\n```\n\n##### `Enumerable#each` vs `for` loop [code](code/enumerable/each-vs-for-loop.rb)\n\n```\n$ ruby -v code/enumerable/each-vs-for-loop.rb\nruby 2.2.0preview1 (2014-09-17 trunk 47616) [x86_64-darwin14]\n\nCalculating -------------------------------------\n            For loop    17.111k i/100ms\n               #each    18.464k i/100ms\n-------------------------------------------------\n            For loop    198.517k (± 5.3%) i/s -    992.438k\n               #each    208.157k (± 5.0%) i/s -      1.052M\n\nComparison:\n               #each:   208157.4 i/s\n            For loop:   198517.3 i/s - 1.05x slower\n```\n\n##### `Enumerable#each_with_index` vs `while` loop [code](code/enumerable/each_with_index-vs-while-loop.rb)\n\n\u003e [rails/rails#12065](https://github.com/rails/rails/pull/12065)\n\n```\n$ ruby -v code/enumerable/each_with_index-vs-while-loop.rb\nruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]\n\nCalculating -------------------------------------\n          While Loop    22.553k i/100ms\n     each_with_index    11.963k i/100ms\n-------------------------------------------------\n          While Loop    240.752k (± 7.1%) i/s -      1.218M\n     each_with_index    126.753k (± 5.9%) i/s -    634.039k\n\nComparison:\n          While Loop:   240752.1 i/s\n     each_with_index:   126753.4 i/s - 1.90x slower\n```\n\n##### `Enumerable#map`...`Array#flatten` vs `Enumerable#flat_map` [code](code/enumerable/map-flatten-vs-flat_map.rb)\n\n\u003e -- @sferik [rails/rails@3413b88](https://github.com/rails/rails/commit/3413b88), [Replace map.flatten with flat_map](https://github.com/rails/rails/commit/817fe31196dd59ee31f71ef1740122b6759cf16d), [Replace map.flatten(1) with flat_map](https://github.com/rails/rails/commit/b11ebf1d80e4fb124f0ce0448cea30988256da59)\n\n```\n$ ruby -v code/enumerable/map-flatten-vs-flat_map.rb\nruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]\n\nCalculating -------------------------------------\nArray#map.flatten(1)     3.315k i/100ms\n   Array#map.flatten     3.283k i/100ms\n      Array#flat_map     5.350k i/100ms\n-------------------------------------------------\nArray#map.flatten(1)     33.801k (± 4.3%) i/s -    169.065k\n   Array#map.flatten     34.530k (± 6.0%) i/s -    173.999k\n      Array#flat_map     55.980k (± 5.0%) i/s -    283.550k\n\nComparison:\n      Array#flat_map:    55979.6 i/s\n   Array#map.flatten:    34529.6 i/s - 1.62x slower\nArray#map.flatten(1):    33800.6 i/s - 1.66x slower\n```\n\n##### `Enumerable#reverse.each` vs `Enumerable#reverse_each` [code](code/enumerable/reverse-each-vs-reverse_each.rb)\n\n\u003e `Enumerable#reverse` allocates an extra array.  \u003cbr\u003e\n\u003e `Enumerable#reverse_each` yields each value without allocating an extra array. \u003cbr\u003e\n\u003e This is the reason why `Enumerable#reverse_each` exists. \u003cbr\u003e\n\u003e -- @sferik [rails/rails#17244](https://github.com/rails/rails/pull/17244)\n\n```\n$ ruby -v code/enumerable/reverse-each-vs-reverse_each.rb\nruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]\n\nCalculating -------------------------------------\n  Array#reverse.each    16.746k i/100ms\n  Array#reverse_each    18.590k i/100ms\n-------------------------------------------------\n  Array#reverse.each    190.729k (± 4.8%) i/s -    954.522k\n  Array#reverse_each    216.060k (± 4.3%) i/s -      1.078M\n\nComparison:\n  Array#reverse_each:   216060.5 i/s\n  Array#reverse.each:   190729.1 i/s - 1.13x slower\n```\n\n##### `Enumerable#sort_by.first` vs `Enumerable#min_by` [code](code/enumerable/sort_by-first-vs-min_by.rb)\n`Enumerable#sort_by` performs a sort of the enumerable and allocates a\nnew array the size of the enumerable.  `Enumerable#min_by` doesn't\nperform a sort or allocate an array the size of the enumerable.\nSimilar comparisons hold for `Enumerable#sort_by.last` vs\n`Enumerable#max_by`, `Enumerable#sort.first` vs `Enumerable#min`, and\n`Enumerable#sort.last` vs `Enumerable#max`.\n\n```\n$ ruby -v code/enumerable/sort_by-first-vs-min_by.rb\nruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]\nWarming up --------------------------------------\n   Enumerable#min_by    15.170k i/100ms\nEnumerable#sort_by...first\n                        10.413k i/100ms\nCalculating -------------------------------------\n   Enumerable#min_by    157.877k (± 0.9%) i/s -    804.010k in   5.093048s\nEnumerable#sort_by...first\n                        106.831k (± 1.3%) i/s -    541.476k in   5.069403s\n\nComparison:\n   Enumerable#min_by:   157877.0 i/s\nEnumerable#sort_by...first:   106831.1 i/s - 1.48x  slower\n```\n\n##### `Enumerable#detect` vs `Enumerable#select.first` [code](code/enumerable/select-first-vs-detect.rb)\n\n```\n$ ruby -v code/enumerable/select-first-vs-detect.rb\nruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]\n\nCalculating -------------------------------------\nEnumerable#select.first  8.515k i/100ms\n   Enumerable#detect    33.885k i/100ms\n-------------------------------------------------\nEnumerable#select.first  89.757k (± 5.0%) i/s -      1.797M\n   Enumerable#detect    434.304k (± 5.2%) i/s -      8.675M\n\nComparison:\n   Enumerable#detect:   434304.2 i/s\nEnumerable#select.first:    89757.4 i/s - 4.84x slower\n```\n\n##### `Enumerable#select.last` vs `Enumerable#reverse.detect` [code](code/enumerable/select-last-vs-reverse-detect.rb)\n\n```\n$ ruby -v code/enumerable/select-last-vs-reverse-detect.rb\nruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]\n\nCalculating -------------------------------------\nEnumerable#reverse.detect 62.636k i/100ms\nEnumerable#select.last    11.687k i/100ms\n-------------------------------------------------\nEnumerable#reverse.detect 1.263M (± 8.2%) i/s -      6.326M\nEnumerable#select.last  119.387k (± 5.7%) i/s -    596.037k\n\nComparison:\nEnumerable#reverse.detect:  1263100.2 i/s\nEnumerable#select.last:     119386.8 i/s - 10.58x slower\n```\n\n##### `Enumerable#sort` vs `Enumerable#sort_by` [code](code/enumerable/sort-vs-sort_by.rb)\n\n```\n$ ruby -v code/enumerable/sort-vs-sort_by.rb\nruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]\n\nCalculating -------------------------------------\nEnumerable#sort_by (Symbol#to_proc) 2.680k i/100ms\n  Enumerable#sort_by                2.462k i/100ms\n     Enumerable#sort                1.320k i/100ms\n-------------------------------------------------\nEnumerable#sort_by (Symbol#to_proc) 25.916k (± 4.4%) i/s -    131.320k\n  Enumerable#sort_by                24.650k (± 5.1%) i/s -    125.562k\n     Enumerable#sort                14.018k (± 5.6%) i/s -     69.960k\n\nComparison:\nEnumerable#sort_by (Symbol#to_proc):    25916.1 i/s\n  Enumerable#sort_by:                   24650.2 i/s - 1.05x slower\n     Enumerable#sort:                   14018.3 i/s - 1.85x slower\n```\n\n##### `Enumerable#inject Symbol` vs `Enumerable#inject Proc` [code](code/enumerable/inject-symbol-vs-block.rb)\n\nOf note, `to_proc` for 1.8.7 is considerable slower than the block format\n\n```\n$ ruby -v code/enumerable/inject-symbol-vs-block.rb\nruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-darwin14]\nWarming up --------------------------------------\n       inject symbol     1.893k i/100ms\n      inject to_proc     1.583k i/100ms\n        inject block     1.390k i/100ms\nCalculating -------------------------------------\n       inject symbol     19.001k (± 3.8%) i/s -     96.543k\n      inject to_proc     15.958k (± 3.5%) i/s -     80.733k\n        inject block     14.063k (± 3.9%) i/s -     70.890k\n\nComparison:\n       inject symbol:    19001.5 i/s\n      inject to_proc:    15958.3 i/s - 1.19x slower\n        inject block:    14063.1 i/s - 1.35x slower\n```\n\n### Date\n\n##### `Date.iso8601` vs `Date.parse` [code](code/date/iso8601-vs-parse.rb)\n\nWhen expecting well-formatted data from e.g. an API, `iso8601` is faster and will raise an `ArgumentError` on malformed input.\n\n```\n$ ruby -v code/date/iso8601-vs-parse.rb\nruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-darwin17]\nWarming up --------------------------------------\n        Date.iso8601    28.880k i/100ms\n          Date.parse    15.805k i/100ms\nCalculating -------------------------------------\n        Date.iso8601    328.035k (± 4.7%) i/s -      1.646M in   5.029287s\n          Date.parse    175.546k (± 3.8%) i/s -    885.080k in   5.049444s\n\nComparison:\n        Date.iso8601:   328035.3 i/s\n          Date.parse:   175545.9 i/s - 1.87x  slower\n```\n\n### Hash\n\n##### `Hash#[]` vs `Hash#fetch` [code](code/hash/bracket-vs-fetch.rb)\n\nIf you use Ruby 2.2, `Symbol` could be more performant than `String` as `Hash` keys.\nRead more regarding this: [Symbol GC in Ruby 2.2](http://www.sitepoint.com/symbol-gc-ruby-2-2/) and [Unraveling String Key Performance in Ruby 2.2](http://www.sitepoint.com/unraveling-string-key-performance-ruby-2-2/).\n\n```\n$ ruby -v code/hash/bracket-vs-fetch.rb\nruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]\n\nCalculating -------------------------------------\n     Hash#[], symbol   143.850k i/100ms\n  Hash#fetch, symbol   137.425k i/100ms\n     Hash#[], string   143.083k i/100ms\n  Hash#fetch, string   120.417k i/100ms\n-------------------------------------------------\n     Hash#[], symbol      7.531M (± 6.6%) i/s -     37.545M\n  Hash#fetch, symbol      6.644M (± 8.2%) i/s -     32.982M\n     Hash#[], string      6.657M (± 7.7%) i/s -     33.195M\n  Hash#fetch, string      3.981M (± 8.7%) i/s -     19.748M\n\nComparison:\n     Hash#[], symbol:  7531355.8 i/s\n     Hash#[], string:  6656818.8 i/s - 1.13x slower\n  Hash#fetch, symbol:  6643665.5 i/s - 1.13x slower\n  Hash#fetch, string:  3981166.5 i/s - 1.89x slower\n```\n\n##### `Hash#dig` vs `Hash#[]` vs `Hash#fetch` [code](code/hash/dig-vs-[]-vs-fetch.rb)\n\n[Ruby 2.3 introduced `Hash#dig`](http://ruby-doc.org/core-2.3.0/Hash.html#method-i-dig) which is a readable\nand performant option for retrieval from a nested hash, returning `nil` if an extraction step fails.\nSee [#102 (comment)](https://github.com/fastruby/fast-ruby/pull/102#issuecomment-198827506) for more info.\n\n```\n$ ruby -v code/hash/dig-vs-\\[\\]-vs-fetch.rb\nruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]\n\nCalculating -------------------------------------\n            Hash#dig      5.719M (± 6.1%) i/s -     28.573M in   5.013997s\n             Hash#[]      6.066M (± 6.9%) i/s -     30.324M in   5.025614s\n          Hash#[] ||      5.366M (± 6.5%) i/s -     26.933M in   5.041403s\n          Hash#[] \u0026\u0026      2.782M (± 4.8%) i/s -     13.905M in   5.010328s\n          Hash#fetch      4.101M (± 6.1%) i/s -     20.531M in   5.024945s\n Hash#fetch fallback      2.975M (± 5.5%) i/s -     14.972M in   5.048880s\n\nComparison:\n             Hash#[]:  6065791.0 i/s\n            Hash#dig:  5719290.9 i/s - same-ish: difference falls within error\n          Hash#[] ||:  5366226.5 i/s - same-ish: difference falls within error\n          Hash#fetch:  4101102.1 i/s - 1.48x slower\n Hash#fetch fallback:  2974906.9 i/s - 2.04x slower\n          Hash#[] \u0026\u0026:  2781646.6 i/s - 2.18x slower\n```\n\n##### `Hash[]` vs `Hash#dup` [code](code/hash/bracket-vs-dup.rb)\n\nSource: http://tenderlovemaking.com/2015/02/11/weird-stuff-with-hashes.html\n\n\u003e Does this mean that you should switch to Hash[]?\n\u003e Only if your benchmarks can prove that it’s a bottleneck.\n\u003e Please please please don’t change all of your code because\n\u003e this shows it’s faster. Make sure to measure your app performance first.\n\n```\n$ ruby -v code/hash/bracket-vs-dup.rb\nruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]\n\nCalculating -------------------------------------\n              Hash[]    29.403k i/100ms\n            Hash#dup    16.195k i/100ms\n-------------------------------------------------\n              Hash[]    343.987k (± 8.7%) i/s -      1.735M\n            Hash#dup    163.516k (±10.2%) i/s -    825.945k\n\nComparison:\n              Hash[]:   343986.5 i/s\n            Hash#dup:   163516.3 i/s - 2.10x slower\n```\n\n##### `Hash#fetch` with argument vs `Hash#fetch` + block [code](code/hash/fetch-vs-fetch-with-block.rb)\n\n\u003e Note that the speedup in the block version comes from avoiding repeated \u003cbr\u003e\n\u003e construction of the argument. If the argument is a constant, number symbol or \u003cbr\u003e\n\u003e something of that sort the argument version is actually slightly faster \u003cbr\u003e\n\u003e See also [#39 (comment)](https://github.com/fastruby/fast-ruby/issues/39#issuecomment-103989335)\n\n```\n$ ruby -v code/hash/fetch-vs-fetch-with-block.rb\nruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin13]\nCalculating -------------------------------------\n  Hash#fetch + const   129.868k i/100ms\n  Hash#fetch + block   125.254k i/100ms\n    Hash#fetch + arg   121.155k i/100ms\n-------------------------------------------------\n  Hash#fetch + const      7.031M (± 7.0%) i/s -     34.934M\n  Hash#fetch + block      6.815M (± 4.2%) i/s -     34.069M\n    Hash#fetch + arg      4.753M (± 5.6%) i/s -     23.746M\n\nComparison:\n  Hash#fetch + const:  7030600.4 i/s\n  Hash#fetch + block:  6814826.7 i/s - 1.03x slower\n    Hash#fetch + arg:  4752567.2 i/s - 1.48x slower\n```\n\n##### `Hash#each_key` instead of `Hash#keys.each` [code](code/hash/keys-each-vs-each_key.rb)\n\n\u003e `Hash#keys.each` allocates an array of keys;  \u003cbr\u003e\n\u003e `Hash#each_key` iterates through the keys without allocating a new array.  \u003cbr\u003e\n\u003e This is the reason why `Hash#each_key` exists.  \u003cbr\u003e\n\u003e —— @sferik [rails/rails#17099](https://github.com/rails/rails/pull/17099)\n\n```\n$ ruby -v code/hash/keys-each-vs-each_key.rb\nruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]\n\nCalculating -------------------------------------\n      Hash#keys.each    56.690k i/100ms\n       Hash#each_key    59.658k i/100ms\n-------------------------------------------------\n      Hash#keys.each    869.262k (± 5.0%) i/s -      4.365M\n       Hash#each_key      1.049M (± 6.0%) i/s -      5.250M\n\nComparison:\n       Hash#each_key:  1049161.6 i/s\n      Hash#keys.each:   869262.3 i/s - 1.21x slower\n```\n\n#### `Hash#key?` instead of `Hash#keys.include?` [code](code/hash/keys-include-vs-key.rb)\n\n\u003e `Hash#keys.include?` allocates an array of keys and performs an O(n) search; \u003cbr\u003e\n\u003e `Hash#key?` performs an O(1) hash lookup without allocating a new array.\n\n```\n$ ruby -v code/hash/keys-include-vs-key.rb\nruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]\n\nCalculating -------------------------------------\n  Hash#keys.include?      8.612k (± 2.5%) i/s -     43.248k in   5.024749s\n           Hash#key?      6.366M (± 5.5%) i/s -     31.715M in   5.002276s\n\nComparison:\n           Hash#key?:  6365855.5 i/s\n  Hash#keys.include?:     8612.4 i/s - 739.15x  slower\n```\n\n##### `Hash#value?` instead of `Hash#values.include?` [code](code/hash/values-include-vs-value.rb)\n\n\u003e `Hash#values.include?` allocates an array of values and performs an O(n) search; \u003cbr\u003e\n\u003e `Hash#value?` performs an O(n) search without allocating a new array.\n\n```\n$ ruby -v code/hash/values-include-vs-value.rb\nruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]\n\nCalculating -------------------------------------\nHash#values.include?     23.187k (± 4.3%) i/s -    117.720k in   5.086976s\n         Hash#value?     38.395k (± 1.0%) i/s -    194.361k in   5.062696s\n\nComparison:\n         Hash#value?:    38395.0 i/s\nHash#values.include?:    23186.8 i/s - 1.66x  slower\n```\n\n##### `Hash#merge!` vs `Hash#[]=` [code](code/hash/merge-bang-vs-\\[\\]=.rb)\n\n```\n$ ruby -v code/hash/merge-bang-vs-\\[\\]=.rb\nruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]\n\nCalculating -------------------------------------\n         Hash#merge!     1.023k i/100ms\n            Hash#[]=     2.844k i/100ms\n-------------------------------------------------\n         Hash#merge!     10.653k (± 4.9%) i/s -     53.196k\n            Hash#[]=     28.287k (±12.4%) i/s -    142.200k\n\nComparison:\n            Hash#[]=:    28287.1 i/s\n         Hash#merge!:    10653.3 i/s - 2.66x slower\n```\n\n##### `Hash#update` vs `Hash#[]=` [code](code/hash/update-vs-\\[\\]=.rb)\n\n```\n$ ruby -v code/hash/update-vs-\\[\\]=.rb\nruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-darwin18]\n\nWarming up --------------------------------------\n            Hash#[]=     7.453k i/100ms\n         Hash#update     4.311k i/100ms\nCalculating -------------------------------------\n            Hash#[]=     74.764k (± 1.9%) i/s -    380.103k in   5.085962s\n         Hash#update     43.220k (± 0.8%) i/s -    219.861k in   5.087364s\n\nComparison:\n            Hash#[]=:    74764.0 i/s\n         Hash#update:    43220.1 i/s - 1.73x  (± 0.00) slower\n```\n\n##### `Hash#merge` vs `Hash#**other` [code](code/hash/merge-vs-double-splat-operator.rb)\n\n```\n$ ruby -v code/hash/merge-vs-double-splat-operator.rb\nruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin15]\nWarming up --------------------------------------\n        Hash#**other    64.624k i/100ms\n          Hash#merge    38.827k i/100ms\nCalculating -------------------------------------\n        Hash#**other    798.397k (± 6.9%) i/s -      4.007M in   5.053516s\n          Hash#merge    434.171k (± 4.5%) i/s -      2.174M in   5.018927s\n\nComparison:\n        Hash#**other:   798396.6 i/s\n          Hash#merge:   434170.8 i/s - 1.84x  slower\n```\n\n##### `Hash#merge` vs `Hash#merge!` [code](code/hash/merge-vs-merge-bang.rb)\n\n```\n$ ruby -v code/hash/merge-vs-merge-bang.rb\nruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]\n\nCalculating -------------------------------------\n          Hash#merge    39.000  i/100ms\n         Hash#merge!     1.008k i/100ms\n-------------------------------------------------\n          Hash#merge    409.610  (± 7.6%) i/s -      2.067k\n         Hash#merge!      9.830k (± 5.8%) i/s -     49.392k\n\nComparison:\n         Hash#merge!:     9830.3 i/s\n          Hash#merge:      409.6 i/s - 24.00x slower\n```\n\n##### `{}#merge!(Hash)` vs `Hash#merge({})` vs `Hash#dup#merge!({})` [code](code/hash/merge-bang-vs-merge-vs-dup-merge-bang.rb)\n\n\u003e When we don't want to modify the original hash, and we want duplicates to be created \u003cbr\u003e\n\u003e See [#42](https://github.com/fastruby/fast-ruby/pull/42#issue-93502261) for more details.\n\n```\n$ ruby -v code/hash/merge-bang-vs-merge-vs-dup-merge-bang.rb\nruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]\n\nCalculating -------------------------------------\n{}#merge!(Hash) do end     2.006k i/100ms\n        Hash#merge({})   762.000  i/100ms\n   Hash#dup#merge!({})   736.000  i/100ms\n-------------------------------------------------\n{}#merge!(Hash) do end     20.055k (± 2.0%) i/s -    100.300k in   5.003322s\n        Hash#merge({})      7.676k (± 1.2%) i/s -     38.862k in   5.063382s\n   Hash#dup#merge!({})      7.440k (± 1.1%) i/s -     37.536k in   5.045851s\n\nComparison:\n{}#merge!(Hash) do end:    20054.8 i/s\n        Hash#merge({}):     7676.3 i/s - 2.61x slower\n   Hash#dup#merge!({}):     7439.9 i/s - 2.70x slower\n```\n\n##### `Hash#sort_by` vs `Hash#sort` [code](code/hash/hash-key-sort_by-vs-sort.rb)\n\nTo sort hash by key.\n\n```\n$ ruby -v code/hash/hash-key-sort_by-vs-sort.rb\nruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14]\n\nCalculating -------------------------------------\n      sort_by + to_h    11.468k i/100ms\n         sort + to_h     8.107k i/100ms\n-------------------------------------------------\n      sort_by + to_h    122.176k (± 6.0%) i/s -    619.272k\n         sort + to_h     81.973k (± 4.7%) i/s -    413.457k\n\nComparison:\n      sort_by + to_h:   122176.2 i/s\n         sort + to_h:    81972.8 i/s - 1.49x slower\n```\n\n##### Native `Hash#slice` vs other slice implementations before native [code](code/hash/slice-native-vs-before-native.rb)\n\nSince ruby 2.5, Hash comes with a `slice` method to select hash members by keys.\n\n```\n$ ruby -v code/hash/slice-native-vs-before-native.rb\nruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]\nWarming up --------------------------------------\nHash#native-slice      178.077k i/100ms\nArray#each             124.311k i/100ms\nArray#each_w/_object   110.818k i/100ms\nHash#select-include     66.972k i/100ms\nCalculating -------------------------------------\nHash#native-slice         2.540M (± 1.5%) i/s -     12.822M in   5.049955s\nArray#each                1.614M (± 1.0%) i/s -      8.080M in   5.007925s\nArray#each_w/_object      1.353M (± 2.6%) i/s -      6.760M in   5.000441s\nHash#select-include     760.944k (± 0.9%) i/s -      3.817M in   5.017123s\n\nComparison:\nHash#native-slice   :  2539515.5 i/s\nArray#each          :  1613665.5 i/s - 1.57x  slower\nArray#each_w/_object:  1352851.8 i/s - 1.88x  slower\nHash#select-include :   760944.2 i/s - 3.34x  slower\n```\n\n\n### Proc \u0026 Block\n\n##### Block vs `Symbol#to_proc` [code](code/proc-and-block/block-vs-to_proc.rb)\n\n\u003e `Symbol#to_proc` is considerably more concise than using block syntax. \u003cbr\u003e\n\u003e ...In some cases, it reduces the number of lines of code. \u003cbr\u003e\n\u003e —— @sferik [rails/rails#16833](https://github.com/rails/rails/pull/16833)\n\n```\n$ ruby -v code/proc-and-block/block-vs-to_proc.rb\nruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]\n\nCalculating -------------------------------------\n               Block     4.632k i/100ms\n      Symbol#to_proc     5.225k i/100ms\n-------------------------------------------------\n               Block     47.914k (± 6.3%) i/s -    240.864k\n      Symbol#to_proc     54.791k (± 4.1%) i/s -    276.925k\n\nComparison:\n      Symbol#to_proc:    54791.1 i/s\n               Block:    47914.3 i/s - 1.14x slower\n```\n\n##### `Proc#call` and block arguments vs `yield` [code](code/proc-and-block/proc-call-vs-yield.rb)\n\nIn MRI Ruby before 2.5, block arguments [are converted to Procs](https://www.omniref.com/ruby/2.2.0/symbols/Proc/yield?#annotation=4087638\u0026line=711), which incurs a heap allocation.\n\n```\n$ ruby -v code/proc-and-block/proc-call-vs-yield.rb\nruby 2.4.4p296 (2018-03-28 revision 63013) [x86_64-darwin18]\nCalculating -------------------------------------\n        block.call      1.967M (± 2.0%) i/s -      9.871M in   5.019328s\n     block + yield      2.147M (± 3.3%) i/s -     10.814M in   5.044319s\n      unused block      2.265M (± 1.9%) i/s -     11.333M in   5.004522s\n             yield     10.436M (± 1.6%) i/s -     52.260M in   5.008851s\n\nComparison:\n             yield: 10436414.0 i/s\n      unused block:  2265399.0 i/s - 4.61x  slower\n     block + yield:  2146619.0 i/s - 4.86x  slower\n        block.call:  1967300.9 i/s - 5.30x  slower\n```\n\nMRI Ruby 2.5 implements [Lazy Proc allocation for block parameters](https://bugs.ruby-lang.org/issues/14045), which speeds things up by about 3x.:\n\n```\n$ ruby -v code/proc-and-block/proc-call-vs-yield.rb\nruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin18]\nCalculating -------------------------------------\n        block.call      1.970M (± 2.3%) i/s -      9.863M in   5.009599s\n     block + yield      9.075M (± 2.6%) i/s -     45.510M in   5.018369s\n      unused block     11.176M (± 2.7%) i/s -     55.977M in   5.012741s\n             yield     10.588M (± 1.9%) i/s -     53.108M in   5.017755s\n\nComparison:\n      unused block: 11176355.0 i/s\n             yield: 10588342.3 i/s - 1.06x  slower\n     block + yield:  9075355.5 i/s - 1.23x  slower\n        block.call:  1969834.0 i/s - 5.67x  slower\n```\n\nMRI Ruby 2.6 implements [an optimization for block.call where a block parameter is passed](https://bugs.ruby-lang.org/issues/14330):\n\n```\n$ ruby -v code/proc-and-block/proc-call-vs-yield.rb\nruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin18]\nCalculating -------------------------------------\n        block.call     10.587M (± 1.2%) i/s -     52.969M in   5.003808s\n     block + yield     12.630M (± 0.3%) i/s -     63.415M in   5.020910s\n      unused block     15.981M (± 0.8%) i/s -     80.255M in   5.022305s\n             yield     15.352M (± 3.1%) i/s -     76.816M in   5.009404s\n\nComparison:\n      unused block: 15980789.4 i/s\n             yield: 15351931.0 i/s - 1.04x  slower\n     block + yield: 12630378.1 i/s - 1.27x  slower\n        block.call: 10587315.1 i/s - 1.51x  slower\n```\n\n### String\n\n##### `String#dup` vs `String#+` [code](code/string/dup-vs-unary-plus.rb)\n\nNote that `String.new` is not the same as the options compared, since it is\nalways `ASCII-8BIT` encoded instead of the script encoding (usually `UTF-8`).\n\n```\n$ ruby -v code/string/dup-vs-unary-plus.rb\nruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-darwin17]\n\nCalculating -------------------------------------\n           String#+@      7.697M (± 1.4%) i/s -     38.634M in   5.020313s\n          String#dup      3.566M (± 1.0%) i/s -     17.860M in   5.008377s\n\nComparison:\n           String#+@:  7697108.3 i/s\n          String#dup:  3566485.7 i/s - 2.16x  slower\n```\n\n##### `String#casecmp` vs  `String#casecmp?` vs `String#downcase + ==` [code](code/string/casecmp-vs-downcase-==.rb)\n\n`String#casecmp?` is available on Ruby 2.4 or later.\nNote that `String#casecmp` only works on characters A-Z/a-z, not all of Unicode.\n\n```\n$ ruby -v code/string/casecmp-vs-downcase-\\=\\=.rb\nruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]\nWarming up --------------------------------------\n     String#casecmp?   395.796k i/100ms\nString#downcase + ==   543.958k i/100ms\n      String#casecmp   730.028k i/100ms\nCalculating -------------------------------------\n     String#casecmp?      3.687M (±10.9%) i/s -     18.602M in   5.158065s\nString#downcase + ==      5.017M (±11.3%) i/s -     25.022M in   5.089175s\n      String#casecmp      6.948M (± 6.0%) i/s -     35.041M in   5.062714s\n\nComparison:\n      String#casecmp:  6948231.0 i/s\nString#downcase + ==:  5017089.5 i/s - 1.38x  (± 0.00) slower\n     String#casecmp?:  3686650.7 i/s - 1.88x  (± 0.00) slower\n```\n\n##### String Concatenation [code](code/string/concatenation.rb)\n\n```\n$ ruby -v code/string/concatenation.rb\nruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]\n\nWarming up --------------------------------------\n            String#+   149.298k i/100ms\n       String#concat   151.505k i/100ms\n       String#append   153.389k i/100ms\n         \"foo\" \"bar\"   195.552k i/100ms\n  \"#{'foo'}#{'bar'}\"   193.784k i/100ms\nCalculating -------------------------------------\n            String#+      2.977M (± 1.1%) i/s -     14.930M in   5.015179s\n       String#concat      3.017M (± 1.3%) i/s -     15.150M in   5.023063s\n       String#append      3.076M (± 1.2%) i/s -     15.492M in   5.037683s\n         \"foo\" \"bar\"      5.370M (± 1.0%) i/s -     26.986M in   5.026271s\n  \"#{'foo'}#{'bar'}\"      5.182M (± 4.6%) i/s -     25.967M in   5.022093s\n\nComparison:\n         \"foo\" \"bar\":  5369594.5 i/s\n  \"#{'foo'}#{'bar'}\":  5181745.7 i/s - same-ish: difference falls within error\n       String#append:  3075719.2 i/s - 1.75x slower\n       String#concat:  3016703.5 i/s - 1.78x slower\n            String#+:  2977282.7 i/s - 1.80x slower\n```\n\n##### `String#match` vs `String.match?` vs `String#start_with?`/`String#end_with?` [code (start)](code/string/start-string-checking-match-vs-start_with.rb) [code (end)](code/string/end-string-checking-match-vs-end_with.rb)\n\nThe regular expression approaches become slower as the tested string becomes\nlonger. For short strings, `String#match?` performs similarly to\n`String#start_with?`/`String#end_with?`.\n\n\u003e :warning: \u003cbr\u003e\n\u003e Sometimes you cant replace regexp with `start_with?`, \u003cbr\u003e\n\u003e for example: `\"a\\nb\" =~ /^b/ #=\u003e 2` but `\"a\\nb\" =~ /\\Ab/ #=\u003e nil`.\u003cbr\u003e\n\u003e :warning: \u003cbr\u003e\n\n```\n$ ruby -v code/string/start-string-checking-match-vs-start_with.rb\nruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-darwin17]\n\nCalculating -------------------------------------\n           String#=~      1.088M (± 4.0%) i/s -      5.471M in   5.034404s\n       String#match?      5.138M (± 5.0%) i/s -     25.669M in   5.008810s\n  String#start_with?      6.314M (± 4.3%) i/s -     31.554M in   5.007207s\n\nComparison:\n  String#start_with?:  6314182.0 i/s\n       String#match?:  5138115.1 i/s - 1.23x  slower\n           String#=~:  1088461.5 i/s - 5.80x  slower\n```\n\n```\n$ ruby -v code/string/end-string-checking-match-vs-end_with.rb\n  ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-darwin17]\n\n  Calculating -------------------------------------\n             String#=~    918.101k (± 6.0%) i/s -      4.650M in   5.084079s\n         String#match?      3.009M (± 6.8%) i/s -     14.991M in   5.005691s\n      String#end_with?      4.548M (± 9.3%) i/s -     22.684M in   5.034115s\n\n  Comparison:\n      String#end_with?:  4547871.0 i/s\n         String#match?:  3008554.5 i/s - 1.51x  slower\n             String#=~:   918100.5 i/s - 4.95x  slower\n```\n\n##### `String#start_with?` vs `String#[].==` [code](code/string/start_with-vs-substring-==.rb)\n\n```\n$ ruby -v code/string/end-string-checking-match-vs-end_with.rb\nruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]\n\nCalculating -------------------------------------\n  String#start_with?      2.047M (± 4.5%) i/s -     10.242M in   5.015146s\n    String#[0, n] ==    711.802k (± 7.3%) i/s -      3.551M in   5.019543s\n   String#[RANGE] ==    651.751k (± 6.2%) i/s -      3.296M in   5.078772s\n   String#[0...n] ==    427.207k (± 5.7%) i/s -      2.136M in   5.019245s\n\nComparison:\n  String#start_with?:  2046618.9 i/s\n    String#[0, n] ==:   711802.3 i/s - 2.88x slower\n   String#[RANGE] ==:   651751.2 i/s - 3.14x slower\n   String#[0...n] ==:   427206.8 i/s - 4.79x slower\n```\n\n##### `Regexp#===` vs `Regexp#match` vs `Regexp#match?` vs `String#match` vs `String#=~` vs `String#match?` [code ](code/string/===-vs-=~-vs-match.rb)\n\n`String#match?` and `Regexp#match?` are available on Ruby 2.4 or later.\nActiveSupport [provides](http://guides.rubyonrails.org/v5.1/active_support_core_extensions.html#match-questionmark)\na forward compatible extension of `Regexp` for older Rubies without the speed\nimprovement.\n\n\u003e :warning: \u003cbr\u003e\n\u003e Sometimes you can't replace `match` with `match?`, \u003cbr\u003e\n\u003e This is only useful for cases where you are checking \u003cbr\u003e\n\u003e for a match and not using the resultant match object. \u003cbr\u003e\n\u003e :warning: \u003cbr\u003e\n\u003e `Regexp#===` is also faster than `String#match` but you need to switch the order of arguments.\n\n```\n$ ruby -v code/string/===-vs-=~-vs-match.rb\nruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]\nCalculating -------------------------------------\n       Regexp#match?      6.994M (± 3.0%) i/s -     35.144M in   5.029647s\n       String#match?      6.909M (± 3.3%) i/s -     34.663M in   5.023177s\n           String#=~      2.784M (± 5.2%) i/s -     13.996M in   5.043168s\n          Regexp#===      2.702M (± 4.5%) i/s -     13.631M in   5.056215s\n        Regexp#match      2.607M (± 4.9%) i/s -     13.025M in   5.009071s\n        String#match      2.362M (± 5.7%) i/s -     11.817M in   5.020344s\n\nComparison:\n       Regexp#match?:  6994107.7 i/s\n       String#match?:  6909055.7 i/s - same-ish: difference falls within error\n           String#=~:  2783577.8 i/s - 2.51x  slower\n          Regexp#===:  2702030.0 i/s - 2.59x  slower\n        Regexp#match:  2607484.0 i/s - 2.68x  slower\n        String#match:  2362314.8 i/s - 2.96x  slower\n```\n\nSee [#59](https://github.com/fastruby/fast-ruby/pull/59) and [#62](https://github.com/fastruby/fast-ruby/pull/62) for discussions.\n\n\n##### `String#gsub` vs `String#sub` vs `String#[]=` [code](code/string/gsub-vs-sub.rb)\n\n```\n$ ruby -v code/string/gsub-vs-sub.rb\nruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]\n\nWarming up --------------------------------------\n         String#gsub    48.360k i/100ms\n          String#sub    45.739k i/100ms\nString#dup[\"string\"]=   59.896k i/100ms\nCalculating -------------------------------------\n         String#gsub    647.666k (± 3.3%) i/s -      3.240M in   5.008504s\n          String#sub    756.665k (± 2.0%) i/s -      3.796M in   5.019235s\nString#dup[\"string\"]=   917.873k (± 1.8%) i/s -      4.612M in   5.026253s\n\nComparison:\nString#dup[\"string\"]=:   917873.1 i/s\n          String#sub:    756664.7 i/s - 1.21x slower\n         String#gsub:    647665.6 i/s - 1.42x slower\n\n\n```\n\n##### `String#gsub` vs `String#tr` [code](code/string/gsub-vs-tr.rb)\n\n\u003e [rails/rails#17257](https://github.com/rails/rails/pull/17257)\n\n```\n$ ruby -v code/string/gsub-vs-tr.rb\nruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]\n\nCalculating -------------------------------------\n         String#gsub    38.268k i/100ms\n           String#tr    83.210k i/100ms\n-------------------------------------------------\n         String#gsub    516.604k (± 4.4%) i/s -      2.602M\n           String#tr      1.862M (± 4.0%) i/s -      9.320M\n\nComparison:\n           String#tr:  1861860.4 i/s\n         String#gsub:   516604.2 i/s - 3.60x slower\n```\n\n##### `String#gsub` vs `String#tr` vs `String#delete` [code](code/string/gsub-vs-tr-vs-delete.rb)\n\n```\nruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux]\n\nCalculating -------------------------------------\n         String#gsub      1.342M (± 1.3%) i/s -      6.816M in   5.079675s\n           String#tr      2.627M (± 1.0%) i/s -     13.387M in   5.096083s\n       String#delete      2.924M (± 0.7%) i/s -     14.889M in   5.093070s\n String#delete const      3.136M (± 2.6%) i/s -     15.866M in   5.064043s\n\nComparison:\n String#delete const:  3135559.1 i/s\n       String#delete:  2923531.8 i/s - 1.07x  slower\n           String#tr:  2627150.5 i/s - 1.19x  slower\n         String#gsub:  1342013.4 i/s - 2.34x  slower\n```\n\n##### `Mutable` vs `Immutable` [code](code/string/mutable_vs_immutable_strings.rb)\n\n```\n$ ruby -v code/string/mutable_vs_immutable_strings.rb\nruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]\n\nCalculating -------------------------------------\n      Without Freeze      7.279M (± 6.6%) i/s -     36.451M in   5.029785s\n         With Freeze      9.329M (± 7.9%) i/s -     46.370M in   5.001345s\n\nComparison:\n         With Freeze:  9329054.3 i/s\n      Without Freeze:  7279203.1 i/s - 1.28x slower\n```\n\n\n##### `String#sub!` vs `String#gsub!` vs `String#[]=` [code](code/string/sub!-vs-gsub!-vs-[]=.rb)\n\nNote that `String#[]` will throw an `IndexError` when given string or regexp not matched.\n\n```\n$ ruby -v code/string/sub\\!-vs-gsub\\!-vs-\\[\\]\\=.rb\nruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]\n\nCalculating -------------------------------------\n  String#['string']=    74.512k i/100ms\n String#sub!'string'    52.801k i/100ms\nString#gsub!'string'    34.480k i/100ms\n  String#[/regexp/]=    55.325k i/100ms\n String#sub!/regexp/    45.770k i/100ms\nString#gsub!/regexp/    27.665k i/100ms\n-------------------------------------------------\n  String#['string']=      1.215M (± 6.2%) i/s -      6.110M\n String#sub!'string'    752.731k (± 6.2%) i/s -      3.749M\nString#gsub!'string'    481.183k (± 4.4%) i/s -      2.414M\n  String#[/regexp/]=    840.615k (± 5.3%) i/s -      4.205M\n String#sub!/regexp/    663.075k (± 7.8%) i/s -      3.295M\nString#gsub!/regexp/    342.004k (± 7.5%) i/s -      1.715M\n\nComparison:\n  String#['string']=:  1214845.5 i/s\n  String#[/regexp/]=:   840615.2 i/s - 1.45x slower\n String#sub!'string':   752731.4 i/s - 1.61x slower\n String#sub!/regexp/:   663075.3 i/s - 1.83x slower\nString#gsub!'string':   481183.5 i/s - 2.52x slower\nString#gsub!/regexp/:   342003.8 i/s - 3.55x slower\n```\n\n##### `String#sub` vs `String#delete_prefix` [code](code/string/sub-vs-delete_prefix.rb)\n\n[Ruby 2.5 introduced](https://bugs.ruby-lang.org/issues/12694) `String#delete_prefix`.\nNote that this can only be used for removing characters from the start of a string.\n\n```\n$ ruby -v code/string/sub-vs-delete_prefix.rb\nruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin17]\nCalculating -------------------------------------\nString#delete_prefix      4.112M (± 1.8%) i/s -     20.707M in   5.037928s\n          String#sub    814.725k (± 1.4%) i/s -      4.088M in   5.018962s\n\nComparison:\nString#delete_prefix:  4111531.1 i/s\n          String#sub:   814725.3 i/s - 5.05x  slower\n```\n\n##### `String#sub` vs `String#chomp` vs `String#delete_suffix` [code](code/string/sub-vs-chomp-vs-delete_suffix.rb)\n\n[Ruby 2.5 introduced](https://bugs.ruby-lang.org/issues/13665) `String#delete_suffix`\nas a counterpart to `delete_prefix`. The performance gain over `chomp` is\nsmall and during some runs the difference falls within the error margin.\nNote that this can only be used for removing characters from the end of a string.\n\n```\n$ ruby -v code/string/sub-vs-chomp-vs-delete_suffix.rb\nruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin17]\nCalculating -------------------------------------\n        String#sub    838.415k (± 1.7%) i/s -      4.214M in   5.027412s\n      String#chomp      3.951M (± 2.1%) i/s -     19.813M in   5.017089s\nString#delete_suffix    4.202M (± 2.1%) i/s -     21.075M in   5.017429s\n\nComparison:\nString#delete_suffix:  4202201.7 i/s\n        String#chomp:  3950921.9 i/s - 1.06x  slower\n          String#sub:   838415.3 i/s - 5.01x  slower\n```\n\n##### `String#unpack1` vs `String#unpack[0]` [code](code/string/unpack1-vs-unpack[0].rb)\n\n[Ruby 2.4.0 introduced `unpack1`](https://bugs.ruby-lang.org/issues/12752) to skip creating the intermediate array object.\n\n```\n$ ruby -v code/string/unpack1-vs-unpack\\[0\\].rb\nruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-darwin17]\nWarming up --------------------------------------\n      String#unpack1   224.291k i/100ms\n    String#unpack[0]   201.870k i/100ms\nCalculating -------------------------------------\n      String#unpack1      4.864M (± 4.2%) i/s -     24.448M in   5.035203s\n    String#unpack[0]      3.778M (± 4.0%) i/s -     18.976M in   5.031253s\n\nComparison:\n      String#unpack1:  4864467.2 i/s\n    String#unpack[0]:  3777815.6 i/s - 1.29x  slower\n```\n\n##### Remove extra spaces (or other contiguous characters) [code](code/string/remove-extra-spaces-or-other-chars.rb)\n\nThe code is tested against contiguous spaces but should work for other chars too.\n\n```\n$ ruby -v code/string/remove-extra-spaces-or-other-chars.rb\nruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux]\nWarming up --------------------------------------\n String#gsub/regex+/     1.644k i/100ms\n      String#squeeze    24.681k i/100ms\nCalculating -------------------------------------\n String#gsub/regex+/     14.668k (± 5.1%) i/s -     73.980k in   5.056887s\n      String#squeeze    372.910k (± 8.4%) i/s -      1.851M in   5.011881s\n\nComparison:\n      String#squeeze:   372910.3 i/s\n String#gsub/regex+/:    14668.1 i/s - 25.42x  slower\n```\n\n### Time\n\n##### `Time.iso8601` vs `Time.parse` [code](code/time/iso8601-vs-parse.rb)\n\nWhen expecting well-formatted data from e.g. an API, `iso8601` is faster and will raise an `ArgumentError` on malformed input.\n\n```\n$ ruby -v code/time/iso8601-vs-parse.rb\nruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-darwin17]\nWarming up --------------------------------------\n        Time.iso8601    10.234k i/100ms\n          Time.parse     4.228k i/100ms\nCalculating -------------------------------------\n        Time.iso8601    114.485k (± 3.5%) i/s -    573.104k in   5.012008s\n          Time.parse     43.711k (± 4.1%) i/s -    219.856k in   5.038349s\n\nComparison:\n        Time.iso8601:   114485.1 i/s\n          Time.parse:    43710.9 i/s - 2.62x  slower\n```\n\n### Range\n\n##### `cover?` vs `include?` [code](code/range/cover-vs-include.rb)\n\n`cover?` only check if it is within the start and end, `include?` needs to traverse the whole range.\n\n```\n$ ruby -v code/range/cover-vs-include.rb\nruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]\n\nCalculating -------------------------------------\n        range#cover?    85.467k i/100ms\n      range#include?     7.720k i/100ms\n       range#member?     7.783k i/100ms\n       plain compare   102.189k i/100ms\n-------------------------------------------------\n        range#cover?      1.816M (± 5.6%) i/s -      9.060M\n      range#include?     83.344k (± 5.0%) i/s -    416.880k\n       range#member?     82.654k (± 5.0%) i/s -    412.499k\n       plain compare      2.581M (± 6.2%) i/s -     12.876M\n\nComparison:\n       plain compare:  2581211.8 i/s\n        range#cover?:  1816038.5 i/s - 1.42x slower\n      range#include?:    83343.9 i/s - 30.97x slower\n       range#member?:    82654.1 i/s - 31.23x slower\n```\n\n\n## Less idiomatic but with significant performance ruby\n\nCheckout: https://github.com/fastruby/fast-ruby/wiki/Less-idiomatic-but-with-significant-performance-difference\n\n\n## Submit New Entry\n\nPlease! [Edit this README.md](https://github.com/fastruby/fast-ruby/edit/main/README.md) then [Submit a Awesome Pull Request](https://github.com/fastruby/fast-ruby/pulls)!\n\n\n## Something went wrong\n\nCode example is wrong? :cry: Got better example? :heart_eyes: Excellent!\n\n[Please open an issue](https://github.com/fastruby/fast-ruby/issues/new) or [Open a Pull Request](https://github.com/fastruby/fast-ruby/pulls) to fix it.\n\nThank you in advance! :wink: :beer:\n\n\n## One more thing\n\n[Share this with your #Rubyfriends! \u003c3](https://twitter.com/intent/tweet?url=http%3A%2F%2Fgit.io%2F4U3xdw\u0026text=Fast%20Ruby%20--%20Common%20Ruby%20Idioms%20inspired%20by%20%40sferik\u0026original_referer=\u0026via=juanitofatas\u0026hashtags=#RubyFriends)\n\nBrought to you by [@JuanitoFatas](https://twitter.com/juanitofatas)\n\nFeel free to talk with me on Twitter! \u003c3\n\n\n## Also Checkout\n\n- [Derailed Benchmarks](https://github.com/schneems/derailed_benchmarks)\n\n  Go faster, off the Rails - Benchmarks for your whole Rails app\n\n- [Benchmarking Ruby](https://speakerdeck.com/davystevenson/benchmarking-ruby)\n\n  Talk by Davy Stevenson @ RubyConf 2014.\n\n- [davy/benchmark-bigo](https://github.com/davy/benchmark-bigo)\n\n  Provides Big O notation benchmarking for Ruby.\n\n- [The Ruby Challenge](https://www.youtube.com/watch?v=aDeP7FGQBig)\n\n  Talk by Prem Sichanugrist @ Ruby Kaigi 2014.\n\n- [Fasterer](https://github.com/DamirSvrtan/fasterer)\n\n  Make your Rubies go faster with this command line tool.\n\n\n## License\n\n![CC-BY-SA](CC-BY-SA.png)\n\nThis work is licensed under a [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/).\n\n\n## Code License\n\n### CC0 1.0 Universal\n\nTo the extent possible under law, @JuanitoFatas has waived all copyright and related or neighboring rights to \"fast-ruby\".\n\nThis work belongs to the community.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastruby%2Ffast-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffastruby%2Ffast-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastruby%2Ffast-ruby/lists"}