Created
April 11, 2019 03:43
-
-
Save kamipo/971dfe0891f0fe1ec7db8ab31f016435 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
# frozen_string_literal: true | |
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
gem "rails", github: "rails/rails" | |
gem "sqlite3" | |
gem "benchmark-ips" | |
end | |
require "active_record" | |
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") | |
ActiveRecord::Schema.define do | |
create_table :users, force: true do |t| | |
t.string :name | |
t.timestamps null: false | |
end | |
create_table :topics, force: true do |t| | |
t.string :title | |
t.integer :user_id | |
t.timestamps null: false | |
end | |
end | |
class Topic < ActiveRecord::Base | |
belongs_to :user | |
end | |
class User < ActiveRecord::Base | |
has_many :topics | |
end | |
user = User.create!(name: "user name") | |
topic = user.topics.build(title: "topic title") | |
Benchmark.ips do |x| | |
x.report("changed?") { topic.changed? } | |
x.report("changed") { topic.changed } | |
x.report("changes") { topic.changes } | |
x.report("changed_attributes") { topic.changed_attributes } | |
x.report("title_change") { topic.title_change } | |
x.report("title_was") { topic.title_was } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment