We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
exploding zipped rows to flatten them is unnecessary since Hash[] takes a 2-d array
Hash[]
def ordered_map_for columns, row h = Hash[*columns.zip(row).flatten] row.each_with_index { |r, i| h[i] = r } h end def ordered_map_for2 columns, row h = Hash[columns.zip(row)] # columns.zip(row) {|k, v| h[k.to_sym] = v} row.each_with_index {|r, i| h[i]=r} h end require 'benchmark' columns = %w(a b c d e f g h i j k l m n o p q r s) row = %w(1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9) n = 100000 Benchmark.bm do |x| x.report("old ") { n.times do ; ordered_map_for columns, row; end } x.report("new ") { n.times do ; ordered_map_for2 columns, row; end } end ####################### user system total real old 2.730000 0.040000 2.770000 ( 2.826577) new 2.200000 0.030000 2.230000 ( 2.062929) [Finished in 5.3s]
The text was updated successfully, but these errors were encountered:
Don't flatten row array before passing to Hash#[]
abaf8b2
Fixes #154
13a5e35
Successfully merging a pull request may close this issue.
exploding zipped rows to flatten them is unnecessary since
Hash[]
takes a 2-d arrayThe text was updated successfully, but these errors were encountered: