Issue #12453 has been updated by Hiroshi SHIBATA.

Status changed from Open to Feedback

----------------------------------------
Bug #12453: 2.3.1p112 version running demo of array methods about 3x slower than running it with 2.2.0p0 version
https://bugs.ruby-lang.org/issues/12453#change-59332

* Author: Harlin Seritt
* Status: Feedback
* Priority: Normal
* Assignee: 
* ruby -v: 
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
The 2.3.1p112 version ran a script that had a very simple demo of array methods close to 3x slower than running it with 2.2.0p0 version. My test environment is Ubuntu 14.04. 

Steps to replicate:

1. Add the following code to example.rb:

~~~
#!/usr/bin/env ruby2

require 'set'

def display_names name_list

  puts '****************************'
  name_list.each do |name|
      puts name
  end
  puts "\n"
end

names = ['Bob', 'Jack', 'Jill', 'Mike', 'John', 'Jim', 'Lisa']

name_list = []

names.each do |name|
  name_list.push name
end

display_names name_list

more_names = ['Mark', 'Matt', 'Luke', 'Juan', 'Jose']
name_list.concat more_names
display_names name_list

puts 'Put Alfa at the front of the line ...'
name_list.insert 0, 'Alfa'
display_names name_list

puts 'Remove Bob from the list ...'
name_list.delete 'Bob'
display_names name_list

puts 'Remove the first and last ...'
name_list.delete_at 0
name_list.pop
display_names name_list

puts 'Clear the whole list ...'
name_list.clear
display_names name_list

puts 'Fill it with names again ...'
name_list = Array.new names
display_names name_list

puts 'Get the index of "Mike" ...'
puts name_list.index 'Mike'

puts 'Get the count of "Mike" in name_list ...'
puts name_list.count 'Mike'

puts 'Sort name_list by alphabetical order ...'
name_list.sort
display_names name_list

puts "Now let's reverse them ..."
name_list.reverse
display_names name_list

puts 'Slice the 2nd through 4th values ...'
display_names name_list.slice 1, 4

puts 'Inserting Charles at the 3rd position ...'
name_list.insert 2, 'Charles'
display_names name_list

puts 'Now removing Charles ...'
name_list.delete_at 2
display_names name_list

puts "Let's switch to numbers ..."
num_list = [5, 7, 9, 2, 4, 6]
display_names num_list

puts "Let's double them ..."
doubles = num_list.map{|i| i * 2}
display_names doubles

puts "Ok, now to sets ..."
fruits = Set.new ['banana', 'orange', 'apple', 'apple', 'grapes']
display_names fruits
~~~

2. Run using these versions:

ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux]

ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]

OBSERVED BEHAVIOR:

3. My times when I run 2.2.0p0:

real	0m0.071s
user	0m0.064s
sys	0m0.004s

4. My times when I run 2.3.1p112:

real	0m0.191s
user	0m0.093s
sys	0m0.107s

EXPECTED BEHAVIOR:

My expectations are that Ruby with the newer version should be getting faster rather than slower.

---Files--------------------------------
example5.rb (1.77 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>