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

Initialize symbols instead of mapping to_sym on the set of strings #21249

Merged
merged 1 commit into from
Aug 15, 2015

Conversation

rodzyn
Copy link
Contributor

@rodzyn rodzyn commented Aug 15, 2015

We have %i so no need to use %w with map(&:to_sym)

require 'benchmark/ips'
require 'set'

Benchmark.ips do |x|
  x.report('%w') do
    Set.new %w(
      @_action_name @_response_body @_formats @_prefixes @_config
      @_view_context_class @_view_renderer @_lookup_context
      @_routes @_db_runtime
    ).map(&:to_sym)
  end

  x.report('%i') do
    Set.new %i(
      @_action_name @_response_body @_formats @_prefixes @_config
      @_view_context_class @_view_renderer @_lookup_context
      @_routes @_db_runtime
    )
  end
end

Calculating -------------------------------------
                  %w     6.162k i/100ms
                  %i     8.277k i/100ms
-------------------------------------------------
                  %w     63.862k (±10.4%) i/s -    320.424k
                  %i     84.348k (±12.2%) i/s -    422.127k

rafaelfranca added a commit that referenced this pull request Aug 15, 2015
Initialize symbols instead of mapping to_sym on the set of strings
@rafaelfranca rafaelfranca merged commit 8ec185a into rails:master Aug 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants