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 pg gem scope_all benchmark #76

Merged
merged 1 commit into from Jul 26, 2017
Jump to file or symbol
Failed to load files and symbols.
+51 −0
Diff settings

Always

Just for now

Copy path View file
@@ -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'
Copy path View file
@@ -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" }

This comment has been minimized.

@SamSaffron

SamSaffron May 22, 2017

Member

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

This comment has been minimized.

@bmarkons

bmarkons May 23, 2017

Collaborator

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

This comment has been minimized.

@SamSaffron

SamSaffron May 23, 2017

Member

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

end
@@ -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
ProTip! Use n and p to navigate between commits in a pull request.