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

ermolaev commented Jan 17, 2020

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'}
ermolaev added 2 commits Jan 17, 2020
@SamSaffron
Copy link
Member

SamSaffron commented Jan 19, 2020

Nice one, looks good to me!

@SamSaffron
Copy link
Member

SamSaffron commented Jan 19, 2020

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

This comment has been minimized.

Copy link
@ermolaev

ermolaev Jan 20, 2020

Author Contributor

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

This comment has been minimized.

Copy link
@SamSaffron

SamSaffron Jan 21, 2020

Member

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

SamSaffron commented Jan 21, 2020

cool lets try this out, thanks!

@SamSaffron SamSaffron merged commit ad86f7e into discourse:master Jan 21, 2020
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.