Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env ruby
# encoding: utf-8
# frozen_string_literal: true
require 'benchmark'
require 'pg'
conn = PG.connect host: '127.0.0.1', dbname: 'dbname', user: 'root', password: 'root'
# conn = PG.connect host: '127.0.0.1', dbname: 'dbname', user: 'postgres', password: 'postgres', port: 12548 # container
values = []
query = 'SELECT * FROM users LIMIT 1000'
measure = Benchmark.measure do
conn.exec(query).each do |row|
values << row
end
end
puts "'#{query}' => #{measure}", values.map(&:to_json).join(' ')[0..800]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment