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

add query_array #10

Merged
merged 3 commits into from Jan 21, 2020
Merged

add query_array #10

merged 3 commits into from Jan 21, 2020

Conversation

ermolaev
Copy link
Contributor

query_array faster query on 30% and comfortably use convert to hash in some cases

p conn.query_array("select 1 as a, '2' as b union select 3, 'e'").to_h
# {1 => '2', 3 => 'e'}

@SamSaffron
Copy link
Member

Nice one, looks good to me!

@SamSaffron
Copy link
Member

Hmmm, query_single in theory should be fastest in lots of cases, can you add that to the readme as well?


# Comparison:
# array: 13041.2 i/s
# string: 4254.9 i/s - 3.06x slower
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in next PR I suggest replaced code

  s = +""
  Topic.limit(1000).order(:id).pluck(:id, :title).each do |id, title|
    s << id.to_s
    s << title
  end
  s

to

  Topic.limit(1000).order(:id).pluck(:id, :title).each do |id, title|
    [id, title]
  end

because use string add unnecessary overhead into benchmarks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep in mind, the benchmark is meant to create the strings, the idea behind it is "What is the fastest way of generating the same exact string from multiple libraries.

@SamSaffron
Copy link
Member

cool lets try this out, thanks!

@SamSaffron SamSaffron merged commit ad86f7e into discourse:master Jan 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants