forked from codetriage/CodeTriage
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirty_tracking.rb
46 lines (37 loc) · 1015 Bytes
/
dirty_tracking.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true
require"active_record"
ActiveRecord::Base.establish_connection(adapter: "sqlite3",database: ":memory:")
ActiveRecord::Schema.definedo
create_table:users,force: truedo |t|
t.string:name
t.timestampsnull: false
end
create_table:topics,force: truedo |t|
t.string:title
t.integer:user_id
t.timestampsnull: false
end
end
classTopic < ActiveRecord::Base
belongs_to:user
end
classUser < 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
Benchmark.bm{ |x|
x.report("title_was"){
1_000_000.times{
topic.title_was
}
}
}