Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pg/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
source "https://rubygems.org"

module ::Kernel
def pg_master?
ENV["PG_MASTER"] == '1'
end
end

if pg_master?
gem 'pg', github: 'ged/ruby-pg'
else
gem 'pg', path: '/pg'
end

gem 'benchmark-ips', '~> 2.2.0'
24 changes: 24 additions & 0 deletions pg/benchmarks/pg_scope_all.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'bundler/setup'
require 'pg'
require_relative 'support/benchmark_pg'

conn = PG.connect(
host: ENV.fetch("HOST", "localhost"),
port: ENV.fetch("PORT", "5432"),
dbname: ENV.fetch("DB_NAME", "rubybench"),
user: ENV.fetch("DB_USER", "postgres"),
password: ENV.fetch("DB_PASSWORD", "postgres")
)

conn.exec("DROP TABLE IF EXISTS users;")
conn.exec("CREATE TABLE users ( name varchar(255), email varchar(255), created_at timestamp, updated_at timestamp );")

1000.times do
conn.exec("INSERT INTO users VALUES ('Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 'foobar@email.com');")
end

Benchmark.pg("raw_pg/postgres_scope_all", time: 5) do
str = ""
conn.exec("SELECT * FROM users").each_row{ |row| str << "name: #{row[0]} email: #{row[1]}\n" }
Copy link
Member

Choose a reason for hiding this comment

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

interestingly this can be done a fraction quicker if you avoid the #each_row and instead just use a double while loop iteration cause you can avoid a bunch of block transitions, its very very minor

Copy link
Contributor Author

@bmarkons bmarkons May 23, 2017

Choose a reason for hiding this comment

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

@SamSaffron interesing note 🤔 I guess I should leave it as it is because I used iterating blocks in other scope_all benchmarks?

Copy link
Member

Choose a reason for hiding this comment

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

yeah, it is a distraction, we should focus on getting that graph up on ruby bench, 3 lines on one benchmark

end

12 changes: 12 additions & 0 deletions pg/benchmarks/support/benchmark_pg.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'pg'
require_relative '../../../support/benchmark_runner'

module Benchmark
module PG
def pg(label = nil, version: ::PG::VERSION.to_s, time:, disable_gc: true, warmup: 3, &block)
Benchmark::Runner.run(label, version: version, time: time, disable_gc: disable_gc, warmup: warmup, &block)
end
end

extend Benchmark::PG
end