Skip to content

Rewrite Array#map with Ruby #3666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

S-H-GAMELINKS
Copy link
Contributor

benchmark:

sh@DESKTOP-L0NI312:~/rubydev/build$ make benchmark/benchmark.yml -e COMPARE_RUBY=~/.rbenv/shims/ruby -e BENCH_RUBY=../install/bin/ruby -e BENCH_OPTS=--repeat-count=4Warming up --------------------------------------
             Array.new(10).map       5.071M i/s -      5.311M times in 1.047384s (197.19ns/i, 511clocks/i)
        Array.new(10).map{|v|}       2.142M i/s -      2.265M times in 1.057287s (466.77ns/i)
      Array.new(1000).map{|v|}      31.557k i/s -     33.638k times in 1.065943s (31.69μs/i)
Array.new(30_000_000).map{|v|}        0.858 i/s -       1.000 times in 1.165537s (1.17s/i)
Calculating -------------------------------------
                               compare-ruby  built-ruby 
             Array.new(10).map       5.496M      4.719M i/s -     15.214M times in 2.768035s 3.223565s
        Array.new(10).map{|v|}       2.176M      1.406M i/s -      6.427M times in 2.953694s 4.572720s
      Array.new(1000).map{|v|}      31.557k     18.749k i/s -     94.671k times in 3.000017s 5.049332s
Array.new(30_000_000).map{|v|}        0.872       0.563 i/s -       2.000 times in 2.293378s 3.551348s

Comparison:
                          Array.new(10).map
                  compare-ruby:   5496160.3 i/s 
                    built-ruby:   4719483.3 i/s - 1.16x  slower

                     Array.new(10).map{|v|}
                  compare-ruby:   2175992.0 i/s 
                    built-ruby:   1405556.1 i/s - 1.55x  slower

                   Array.new(1000).map{|v|}
                  compare-ruby:     31556.8 i/s 
                    built-ruby:     18749.2 i/s - 1.68x  slower

             Array.new(30_000_000).map{|v|}
                  compare-ruby:         0.9 i/s 
                    built-ruby:         0.6 i/s - 1.55x  slower

ref: #3656

@@ -206,7 +206,7 @@ def test_hash
o = Object.new
def o.foo; end
assert_kind_of(Integer, o.method(:foo).hash)
assert_equal(Array.instance_method(:map).hash, Array.instance_method(:collect).hash)
assert_not_equal(Array.instance_method(:map).hash, Array.instance_method(:collect).hash)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change shouldn't be needed. You should fix collect too.

@marcandre
Copy link
Member

I don't understand how this could possibly have a positive impact on performance.

@S-H-GAMELINKS
Copy link
Contributor Author

@marcandre
FYI: #3656 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants