-
Notifications
You must be signed in to change notification settings - Fork 6
/
benchmark.rb
80 lines (61 loc) · 1.42 KB
/
benchmark.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
require 'bundler/setup'
require "mysql2"
require "active_record"
require 'light_record'
require 'process_memory'
require 'benchmark'
require 'benchmark/ips'
ActiveRecord::Base.logger = ActiveSupport::Logger.new("/dev/null")
ActiveRecord::Base.establish_connection(
adapter: 'mysql2',
database: 'light_record',
host: 'localhost',
username: 'root',
password: ''
)
class ARSample < ActiveRecord::Base
self.table_name = "sample"
self.primary_key = "policy_id"
end
scope = ARSample.limit(50000)
Benchmark.bm(14) do |x|
x.report("ActiveRecord:") do
scope.to_a
end
x.report("LightRecord:") do
scope.light_records
end
end
GC.disable
puts "TESTING AR"
recorder = ProcessMemory.start_recording
records = []
scope.each do |record|
records << record.to_json
end
recorder.stop
puts "Time spent: #{Time.now - recorder.instance_variable_get(:@start_time)} sec"
puts recorder.report_per_second_pretty
puts
puts "TESTING LR"
recorder = ProcessMemory.start_recording
records2 = []
scope.light_records_each do |record|
records2 << record.to_json
end
recorder.stop
puts "Time spent: #{Time.now - recorder.instance_variable_get(:@start_time)} sec"
puts recorder.report_per_second_pretty
=begin
ar_record = scope.first
lr_record = scope.light_record_first
Benchmark.ips do |x|
x.warmup = 2
x.report("ActiveRecord") do
ar_record.tiv_2012
end
x.report("LightRecord") do
lr_record.tiv_2012
end
end
=end