Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make VALID_DIRECTIONS to Set #29156

Merged
merged 1 commit into from
May 20, 2017

Conversation

kamipo
Copy link
Member

@kamipo kamipo commented May 20, 2017

require "benchmark/ips"
require "set"

array = [:asc, :desc, :ASC, :DESC, "asc", "desc", "ASC", "DESC"]
set   = array.to_set
item  = "DESC"

Benchmark.ips do |x|
  x.report "array" do
    array.include?(item)
  end
  x.report "set" do
    set.include?(item)
  end
end
% ruby array_vs_set.rb
Warming up --------------------------------------
               array   188.441k i/100ms
                 set   229.531k i/100ms
Calculating -------------------------------------
               array      3.508M (± 9.0%) i/s -     17.525M in   5.043058s
                 set      5.134M (± 7.6%) i/s -     25.707M in   5.038921s

```ruby
require "benchmark/ips"
require "set"

array = [:asc, :desc, :ASC, :DESC, "asc", "desc", "ASC", "DESC"]
set   = array.to_set
item  = "DESC"

Benchmark.ips do |x|
  x.report "array" do
    array.include?(item)
  end
  x.report "set" do
    set.include?(item)
  end
end
```

```
% ruby array_vs_set.rb
Warming up --------------------------------------
               array   188.441k i/100ms
                 set   229.531k i/100ms
Calculating -------------------------------------
               array      3.508M (± 9.0%) i/s -     17.525M in   5.043058s
                 set      5.134M (± 7.6%) i/s -     25.707M in   5.038921s
```
@pixeltrix
Copy link
Contributor

In the scheme of things I don't think this will make much difference but thanks anyway! 👍

@pixeltrix pixeltrix merged commit ffa693d into rails:master May 20, 2017
@kamipo kamipo deleted the make_valid_directions_to_set branch May 20, 2017 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants