fast-ruby icon indicating copy to clipboard operation
fast-ruby copied to clipboard

Adds `Enumerable#each_with_object` vs `Enumerable#inject` comparison

Open mateusdeap opened this issue 3 years ago • 1 comments

Solves #6

mateusdeap avatar Sep 19 '22 22:09 mateusdeap

Hey @rishijain, can you review this PR, please?

KostiantynPopovych avatar Sep 24 '22 00:09 KostiantynPopovych

Yup, definitely, rerunning the example, the performance is just about the same. Will close this PR and corresponding issue. For future reference, here are the updated results:

ruby -v code/enumerable/each-with-object-vs-inject.rb
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]
Warming up --------------------------------------
Enumerable#each_with_object
                         1.044k i/100ms
   Enumerable#inject     1.033k i/100ms
Calculating -------------------------------------
Enumerable#each_with_object
                         10.554k (± 1.2%) i/s -     53.244k in   5.045839s
   Enumerable#inject     10.479k (± 0.7%) i/s -     52.683k in   5.027723s

Comparison:
Enumerable#each_with_object:    10553.7 i/s
   Enumerable#inject:    10479.0 i/s - same-ish: difference falls within error

mateusdeap avatar Jun 12 '23 12:06 mateusdeap