forked from codetriage/CodeTriage
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrespond_to.rb
47 lines (38 loc) · 1.11 KB
/
respond_to.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
47
# 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,:email,:username,:password,:birthday,:foo,:bar,:baz,:dog_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",dog_name: "cinco")
user.respond_to?(:name)
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("respond_to"){
1_000_000.times{
user.respond_to?(:dog_name)
}
}
}