ruby/ruby — pull request #537 by ksss (2014-02-18 22:49:20+00:00)
Title: * array.c (rb_ary_shift_m): use shared instead of MEMMOVE if with arguments

Array#shift is not make shared array when arguments is 0,1,2,3.
Therefore, call memmove() even if too big array.

I change make shared array if length over ARY_DEFAULT_SIZE and add test code about this.

I send benchmark this patch.

```ruby
require 'benchmark'

Benchmark.bm do |x|
[10_000,1_000_000,100_000_000].each do |n|
ary = Array.new(n,0)
GC.start
x.report("#{n}:shift"){ ary.shift }
(0..4).each do |i|
ary = Array.new(n,0)
GC.start
x.report("#{n}:shift(#{i})"){ ary.shift(i) }
end
end
end
```

before

```
user system total real
10000:shift 0.000000 0.000000 0.000000 ( 0.000004)
10000:shift(0) 0.000000 0.000000 0.000000 ( 0.000009)
10000:shift(1) 0.000000 0.000000 0.000000 ( 0.000008)
10000:shift(2) 0.000000 0.000000 0.000000 ( 0.000007)
10000:shift(3) 0.000000 0.000000 0.000000 ( 0.000008)
10000:shift(4) 0.000000 0.000000 0.000000 ( 0.000004)
1000000:shift 0.000000 0.000000 0.000000 ( 0.000006)
1000000:shift(0) 0.000000 0.000000 0.000000 ( 0.000750)
1000000:shift(1) 0.000000 0.000000 0.000000 ( 0.000865)
1000000:shift(2) 0.000000 0.000000 0.000000 ( 0.000796)
1000000:shift(3) 0.000000 0.000000 0.000000 ( 0.000774)
1000000:shift(4) 0.000000 0.000000 0.000000 ( 0.000006)
100000000:shift 0.000000 0.000000 0.000000 ( 0.000006)
100000000:shift(0) 0.090000 0.000000 0.090000 ( 0.096063)
100000000:shift(1) 0.090000 0.010000 0.100000 ( 0.093355)
100000000:shift(2) 0.100000 0.000000 0.100000 ( 0.092509)
100000000:shift(3) 0.100000 0.000000 0.100000 ( 0.096386)
100000000:shift(4) 0.000000 0.000000 0.000000 ( 0.000006)
```

after

```
user system total real
10000:shift 0.000000 0.000000 0.000000 ( 0.000005)
10000:shift(0) 0.000000 0.000000 0.000000 ( 0.000004)
10000:shift(1) 0.000000 0.000000 0.000000 ( 0.000003)
10000:shift(2) 0.000000 0.000000 0.000000 ( 0.000004)
10000:shift(3) 0.000000 0.000000 0.000000 ( 0.000004)
10000:shift(4) 0.000000 0.000000 0.000000 ( 0.000004)
1000000:shift 0.000000 0.000000 0.000000 ( 0.000005)
1000000:shift(0) 0.000000 0.000000 0.000000 ( 0.000005)
1000000:shift(1) 0.000000 0.000000 0.000000 ( 0.000006)
1000000:shift(2) 0.000000 0.000000 0.000000 ( 0.000006)
1000000:shift(3) 0.000000 0.000000 0.000000 ( 0.000005)
1000000:shift(4) 0.000000 0.000000 0.000000 ( 0.000006)
100000000:shift 0.000000 0.000000 0.000000 ( 0.000005)
100000000:shift(0) 0.000000 0.000000 0.000000 ( 0.000006)
100000000:shift(1) 0.000000 0.000000 0.000000 ( 0.000006)
100000000:shift(2) 0.000000 0.000000 0.000000 ( 0.000006)
100000000:shift(3) 0.000000 0.000000 0.000000 ( 0.000006)
100000000:shift(4) 0.000000 0.000000 0.000000 ( 0.000006)
```