Project

General

Profile

Actions

Feature #17311

open

Improve performance Array#deconstruct & Array#to_ary

Added by S_H_ (Shun Hiraoka) over 3 years ago. Updated over 3 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:100748]

Description

Improve performance Array#deconstruct & Array#to_ary with Ruby code.

like this.

class Array
  def deconstruct
    return self
  end

  def to_ary
    return self
  end
end

benchmark:

prelude: |
  sary = Array.new(10)
  mary = Array.new(1000)
  lary = Array.new(30_000_000)
benchmark:
  - sary.deconstruct
  - mary.deconstruct
  - lary.deconstruct
  - sary.to_ary
  - mary.to_ary
  - lary.to_ary
loop_count: 20000000


benchmark result:

sh@MyComputer:~/rubydev/build$ make benchmark/benchmark.yml -e COMPARE_RUBY=~/.rbenv/shims/ruby -e BENCH_RUBY=../install/bin/ruby
# Iteration per second (i/s)

|                  |compare-ruby|built-ruby|
|:-----------------|-----------:|---------:|
|sary.deconstruct  |     72.866M|   74.310M|
|                  |           -|     1.02x|
|mary.deconstruct  |     73.665M|   80.049M|
|                  |           -|     1.09x|
|lary.deconstruct  |     74.924M|   86.865M|
|                  |           -|     1.16x|
|sary.to_ary       |     70.203M|   81.387M|
|                  |           -|     1.16x|
|mary.to_ary       |     72.142M|   78.847M|
|                  |           -|     1.09x|
|lary.to_ary       |     70.473M|   86.382M|
|                  |           -|     1.23x|

COMPARE_RUBY is ruby 3.0.0dev (2020-11-07T13:12:22Z master 5823f6c25b) [x86_64-linux]. BENCH_RUBY is ahead of ruby 3.0.0dev (2020-11-07T13:12:22Z master 5823f6c25b) [x86_64-linux].

Also expect to improve the performance of pattern matching using arrays.

PR:
https://github.com/ruby/ruby/pull/3744

Actions #1

Updated by S_H_ (Shun Hiraoka) over 3 years ago

  • Description updated (diff)
Actions

Also available in: Atom PDF

Like0
Like0