forked from palkan/logidze
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion_at_bench.rb
52 lines (36 loc) · 1.02 KB
/
version_at_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
# frozen_string_literal: true
require "benchmark/ips"
require_relative "../config/environment"
# How many records do you want?
N = (ENV["N"] || "100").to_i
# How many records to load in the benchmark?
M = (N / 10)
# How many version each record has?
V = (ENV["V"] || "10").to_i
# Benchmark run time
BM_TIME = (ENV["BM_TIME"] || 5).to_i
BM_WARMUP = [(BM_TIME / 10), 2].max
Benchmarker.cleanup
Benchmarker.populate(N, skip_user: true)
ts1 = Benchmarker.generate_versions(V / 2)
Benchmarker.generate_versions(V / 2)
Benchmark.ips do |x|
x.config(time: BM_TIME, warmup: BM_WARMUP)
x.report("PT AT single") do
PaperTrailUser.random.paper_trail.version_at(ts1)
end
x.report("Logidze AT single") do
LogidzeUser.random.at(time: ts1)
end
x.compare!
end
Benchmark.ips do |x|
x.config(time: BM_TIME, warmup: BM_WARMUP)
x.report("PT AT many") do
PaperTrailUser.random(M).map { |u| u.paper_trail.version_at(ts1) }
end
x.report("Logidze AT many") do
LogidzeUser.random(M).at(time: ts1)
end
x.compare!
end