Skip to content

Commit

Permalink
bench Array#sort methods
Browse files Browse the repository at this point in the history
  • Loading branch information
burningTyger committed Mar 14, 2011
1 parent aefea5a commit 04659a4
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions benchmark/core/array/bench_sort.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require 'benchmark'
require 'benchmark/ips'

Benchmark.ips do |x|
array = %w(Lorem ipsum singulis assentior ei pro ius eu choro verterem his dicta possim epicurei at Atomorum sadipscing ne cum sit ex hinc eros tation Eu mea oblique indoctum sed nostro mandamus recteque ut Ei usu labitur consequuntur Cu postulant consulatu reprimique vim his debet mucius platonem ne mucius facilis scriptorem vim ei)

x.report "sort up" do |times|
i = 0
while i < times
array.sort
i += 1
end
end

x.report "array sort! up" do |times|
i = 0
while i < times
array2 = array.dup
array2.sort!
i += 1
end
end

x.report "sort up and reverse!" do |times|
i = 0
while i < times
array.sort.reverse!
i += 1
end
end

x.report "sort! up and reverse!" do |times|
i = 0
while i < times
array2 = array.dup
array2.sort!.reverse!
i += 1
end
end

x.report "sort down with block" do |times|
i = 0
while i < times
array.sort { |a,b| b <=> a }
i += 1
end
end

x.report "sort! down with block" do |times|
i = 0
while i < times
array2 = array.dup
array2.sort! { |a,b| b <=> a }
i += 1
end
end

end

0 comments on commit 04659a4

Please sign in to comment.