Skip to content

Instantly share code, notes, and snippets.

@jwoertink
Last active June 25, 2018 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwoertink/55f474ddb0d2322e09d32af887a07bc9 to your computer and use it in GitHub Desktop.
Save jwoertink/55f474ddb0d2322e09d32af887a07bc9 to your computer and use it in GitHub Desktop.
require "pg"
require "benchmark"
require "active_record"
ActiveRecord::Base.establish_connection(
adapter: "postgresql",
database: "crystal_orm_test",
username: "postgres",
host: "localhost"
)
class User < ActiveRecord::Base
end
def simple_insert(idx)
u = User.new
u.name = "RubyGuy #{idx}"
u.orm = "activerecord"
u.idx = idx
u.save
end
def simple_select(idx)
User.where(orm: "activerecord").order(id: :asc).map(&:name)
end
def simple_update(idx_value)
u = User.where(orm: "activerecord", idx: idx_value).first
u.name = "Ruby Guy#{idx_value}"
u.save
end
Benchmark.bm do |x|
x.report("activerecord simple_insert") do
1000.times do |i|
simple_insert(i)
end
end
end
Benchmark.bm do |x|
x.report("activerecord simple_select") do
1000.times do |i|
simple_select(i)
end
end
end
Benchmark.bm do |x|
x.report("activerecord simple_update") do
1000.times do |i|
simple_update(i)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment