forked from palkan/logidze
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_bench.rb
64 lines (47 loc) · 1.4 KB
/
update_bench.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# frozen_string_literal: true
require "benchmark/ips"
require_relative "../config/environment"
# Benchmark run time
BM_TIME = (ENV["BM_TIME"] || 5).to_i
BM_WARMUP = [(BM_TIME / 10), 2].max
params = Benchmarker.fake_params.slice(:age, :email)
params2 = Benchmarker.fake_params
Benchmarker.cleanup
Benchmarker.populate(ENV.fetch("N", 1_000).to_i)
class LogidzeUser
# Loading log_data could produce a bit of overhead but it's out of scope for this benchmark
self.ignored_columns += ["log_data"]
end
JSON_COLUMNS = %i[data dump].freeze
Benchmark.ips do |x|
x.config(time: BM_TIME, warmup: BM_WARMUP)
x.report("Plain UPDATE #1") do
User.random.update!(params)
end
x.report("PT UPDATE #1") do
PaperTrailUser.random.update!(params)
end
x.report("Logidze UPDATE #1") do
LogidzeUser.random.update!(params)
end
x.compare!
end
Benchmark.ips do |x|
x.config(time: BM_TIME, warmup: BM_WARMUP)
x.report("Plain UPDATE #2") do
user = User.random
user.update!(params2.except(*JSON_COLUMNS))
user.update!(params2.slice(*JSON_COLUMNS))
end
x.report("PT UPDATE #2") do
user = PaperTrailUser.random
user.update!(params2.except(*JSON_COLUMNS))
user.update!(params2.slice(*JSON_COLUMNS))
end
x.report("Logidze UPDATE #2") do
user = LogidzeUser.random
user.update!(params2.except(*JSON_COLUMNS))
user.update!(params2.slice(*JSON_COLUMNS))
end
x.compare!
end