-
-
Save jwoertink/55f474ddb0d2322e09d32af887a07bc9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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