Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zymtx5g79k/7437eff46b7c84ac972974c6757e150e to your computer and use it in GitHub Desktop.
Save zymtx5g79k/7437eff46b7c84ac972974c6757e150e to your computer and use it in GitHub Desktop.
#!/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