Skip to content

Commit 5489da0

Browse files
committed
[chore] refactor bench update to force updates
1 parent b5c8f58 commit 5489da0

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

bench/benchmark_update.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,29 @@
2727

2828
empty = {}
2929

30+
record_1 = BenchRecord.create.reload
31+
record_2 = BenchRecord.create.reload
32+
record_3 = BenchRecord.create.reload
33+
def record_3.changed_attribute_names_to_save; attribute_names end # will always update all attributes
34+
3035
Benchmark.ips do |x|
3136
x.config(:suite => BenchTestHelper::Suite::INSTANCE)
3237

33-
record = BenchRecord.create.reload
34-
x.report("BenchRecord#update()") do
35-
record.update empty
38+
x.report("BenchRecord#update() [NOOP]") do
39+
record_1.update! empty # base-line expected to be a no-op
3640
end
3741

3842
fields.each do |field, value|
3943
label = value
4044
label = "#{value[0,16]}...(#{value.size})" if value.is_a?(String) && value.size > 16
41-
record = BenchRecord.create.reload
4245
x.report("BenchRecord#update('#{field}' => #{label.inspect})") do
43-
record.update(field => value)
46+
record_2.send "#{field}_will_change!" # forces the change even if the value did not change
47+
record_2.update!(field => value)
4448
end
4549
end
4650

4751
x.report("BenchRecord#update(...)") do
48-
record.update(fields)
52+
record_3.update!(fields)
4953
end
5054

5155
end

0 commit comments

Comments
 (0)