Skip to content

Commit

Permalink
bench Array#reject, #reject\! and #select
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuck Remes committed Mar 9, 2011
1 parent 4e6c655 commit c200dc7
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
43 changes: 43 additions & 0 deletions benchmark/core/array/bench_reject.rb
@@ -0,0 +1,43 @@
require 'benchmark'
require 'benchmark/ips'

Benchmark.ips do |x|
strings = ('a'..'j').to_a
numbers = [-4, -81, 0, 5, 12, -1_000_000, 1, 10, 100, 1000]

x.report "reject string" do |times|
i = 0
while i < times
a = strings.dup
a.reject { |v| v < 'd' }
i += 1
end
end

x.report "reject numbers" do |times|
i = 0
while i < times
a = numbers.dup
a.reject { |v| v < 10 }
i += 1
end
end

x.report "reject! string" do |times|
i = 0
while i < times
a = strings.dup
a.reject! { |v| v < 'd' }
i += 1
end
end

x.report "reject! numbers" do |times|
i = 0
while i < times
a = numbers.dup
a.reject! { |v| v < 10 }
i += 1
end
end
end
25 changes: 25 additions & 0 deletions benchmark/core/array/bench_select.rb
@@ -0,0 +1,25 @@
require 'benchmark'
require 'benchmark/ips'

Benchmark.ips do |x|
strings = ('a'..'j').to_a
numbers = [-4, -81, 0, 5, 12, -1_000_000, 1, 10, 100, 1000]

x.report "select string" do |times|
i = 0
while i < times
a = strings.dup
a.select { |v| v > 'd' }
i += 1
end
end

x.report "select numbers" do |times|
i = 0
while i < times
a = numbers.dup
a.select { |v| v > 10 }
i += 1
end
end
end

0 comments on commit c200dc7

Please sign in to comment.