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 1 commit into from Jul 26, 2017
Jump to file or symbol
Failed to load files and symbols.
+51 −0
Diff settings


Just for now

Copy path View file
@@ -0,0 +1,15 @@
source ""
module ::Kernel
def pg_master?
ENV["PG_MASTER"] == '1'
if pg_master?
gem 'pg', github: 'ged/ruby-pg'
gem 'pg', path: '/pg'
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.', '');")
end"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 May 22, 2017


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 May 23, 2017


@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 May 23, 2017


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

@@ -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), version: version, time: time, disable_gc: disable_gc, warmup: warmup, &block)
extend Benchmark::PG
ProTip! Use n and p to navigate between commits in a pull request.