Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
= Using ActiveRecord (with the regular mysql adapter)
From the rails console:
require 'benchmark'
Benchmark.bm {|x| x.report {User.select(:login).to_a} }
---------------------------------------------------------------------
user system total real
0.730000 0.010000 0.740000 ( 0.803687)
require 'benchmark'
Benchmark.bm {|x| x.report {Yajl.dump(User.select(:login).to_a)} }
---------------------------------------------------------------------
user system total real
1.890000 0.020000 1.910000 ( 1.972127)
# the encode is actually mostly done in ActiveSupport since Yajl's just calling
# each models #to_json method - I'd rather #as_json *always* return a hash or some other
# JSON mappable primitive. See: https://rails.lighthouseapp.com/projects/8994/tickets/4520-as_json-should-only-ever-return-a-hash-array-numeric-string-nil-true-or-false#ticket-4520-2
= Using Mysql2 directly
From the rails console:
require 'benchmark'
config = Rails.configuration.database_configuration[Rails.env]
config.symbolize_keys!
client = Mysql2::Client.new config
Benchmark.bm {|x| x.report {client.query("SELECT login FROM users").to_a} }
---------------------------------------------------------------------
user system total real
0.130000 0.010000 0.140000 ( 0.146628)
require 'benchmark'
config = Rails.configuration.database_configuration[Rails.env]
config.symbolize_keys!
client = Mysql2::Client.new config
Benchmark.bm {|x| x.report {Yajl.dump(client.query("SELECT login FROM users").to_a)} }
---------------------------------------------------------------------
user system total real
0.020000 0.010000 0.030000 ( 0.035003)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment