Skip to content

Commit e3a11f3

Browse files
authored
Merge pull request #1115 from jruby/ips
[chore] update scripts to benchmark-ips
2 parents a3a91e2 + 34c01a3 commit e3a11f3

File tree

7 files changed

+65
-72
lines changed

7 files changed

+65
-72
lines changed

bench/benchmark_create.rb

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,23 @@
2525
'a_timestamp' => Time.now
2626
}
2727

28-
Benchmark.bmbm do |x|
28+
Benchmark.ips do |x|
29+
x.config(:suite => BenchTestHelper::Suite::INSTANCE)
2930

30-
x.report("BenchRecord.create() [#{TIMES}x]") do
31-
TIMES.times do
32-
BenchRecord.create()
33-
end
31+
x.report("BenchRecord.create()") do
32+
BenchRecord.create()
3433
end
3534

3635
fields.each do |field, value|
3736
label = value
3837
label = "#{value[0,16]}...(#{value.size})" if value.is_a?(String) && value.size > 16
39-
x.report("BenchRecord.create('#{field}' => #{label.inspect}) [#{TIMES}x]") do
40-
attrs = Hash.new; attrs[field] = value
41-
TIMES.times do
42-
BenchRecord.create(attrs)
43-
end
38+
x.report("BenchRecord.create('#{field}' => #{label.inspect})") do
39+
BenchRecord.create(field => value)
4440
end
4541
end
4642

47-
x.report("BenchRecord.create(...) [#{TIMES}x]") do
48-
attrs = fields.dup
49-
TIMES.times do
50-
BenchRecord.create(attrs)
51-
end
43+
x.report("BenchRecord.create(...)") do
44+
BenchRecord.create(fields.dup)
5245
end
5346

5447
end

bench/benchmark_find_all.rb

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,21 @@
44

55
BenchTestHelper.gc
66

7-
Benchmark.bmbm do |x|
7+
Benchmark.ips do |x|
8+
x.config(:suite => BenchTestHelper::Suite::INSTANCE)
89

910
total = BenchRecord.count
1011

11-
x.report("BenchRecord.first(10) [#{TIMES}x]") do
12-
TIMES.times do
13-
BenchRecord.first(10)
14-
end
12+
x.report("BenchRecord.first(10)") do
13+
BenchRecord.first(10)
1514
end
1615

17-
x.report("BenchRecord.last(100) [#{TIMES}x]") do
18-
TIMES.times do
19-
BenchRecord.last(100)
20-
end
16+
x.report("BenchRecord.last(100)") do
17+
BenchRecord.last(100)
2118
end
2219

23-
x.report("BenchRecord.limit(100).load [#{TIMES}x]") do
24-
TIMES.times do
25-
BenchRecord.limit(100).load
26-
end
20+
x.report("BenchRecord.limit(100).load") do
21+
BenchRecord.limit(100).load
2722
end
2823

2924
end

bench/benchmark_find_attributes.rb

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,17 @@
44

55
BenchTestHelper.gc
66

7-
Benchmark.bmbm do |x|
7+
Benchmark.ips do |x|
8+
x.config(:suite => BenchTestHelper::Suite::INSTANCE)
89

910
an_id = BenchRecord.last.id
1011

11-
x.report("BenchRecord.find( an_id ) [#{TIMES}x]") do
12-
TIMES.times do
13-
BenchRecord.find( an_id )
14-
end
12+
x.report("BenchRecord.find(an_id)") do
13+
BenchRecord.find( an_id )
1514
end
1615

17-
x.report("BenchRecord.find( an_id ).attributes [#{TIMES}x]") do
18-
TIMES.times do
19-
BenchRecord.find( an_id ).attributes
20-
end
16+
x.report("BenchRecord.find(an_id).attributes") do
17+
BenchRecord.find( an_id ).attributes
2118
end
2219

2320
end

bench/benchmark_helpers.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
require File.expand_path('setup', File.dirname(__FILE__))
22

3-
Benchmark.bmbm do |x|
4-
x.report("ActiveRecord::ConnectionAdapters::Column.string_to_time [#{TIMES}x]") do
5-
TIMES.times do
6-
ActiveRecord::ConnectionAdapters::Column.string_to_time("Wed, 04 Sep 2013 03:00:00 EAT")
7-
end
3+
Benchmark.ips do |x|
4+
x.config(:suite => BenchTestHelper::Suite::INSTANCE)
5+
6+
x.report("ActiveRecord::ConnectionAdapters::Column.string_to_time") do
7+
ActiveRecord::ConnectionAdapters::Column.string_to_time("Wed, 04 Sep 2013 03:00:00 EAT")
88
end
9-
end
9+
end

bench/benchmark_selects.rb

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,21 @@
1919
'*'
2020
]
2121

22-
Benchmark.bmbm do |x|
22+
Benchmark.ips do |x|
23+
x.config(:suite => BenchTestHelper::Suite::INSTANCE)
2324

2425
total = BenchRecord.count
2526
an_id = BenchRecord.last.id
2627

2728
selects.each do |select|
28-
x.report("BenchRecord.select('#{select}').where(id: i).first [#{TIMES}x]") do
29-
TIMES.times do |i|
30-
BenchRecord.select(select).where(id: i % total).first
31-
end
29+
x.report("BenchRecord.select('#{select}').where(id: i).first") do
30+
BenchRecord.select(select).where(id: i % total).first
3231
end
3332
end
3433

3534
selects.each do |select|
36-
x.report("BenchRecord.select('#{select}').where(['id = ?', an_id]).first [#{TIMES}x]") do
37-
TIMES.times do
38-
BenchRecord.select(select).where(['id = ?', an_id]).first
39-
end
35+
x.report("BenchRecord.select('#{select}').where(['id = ?', an_id]).first") do
36+
BenchRecord.select(select).where(['id = ?', an_id]).first
4037
end
4138
end
4239

bench/benchmark_update.rb

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

2828
empty = {}
2929

30-
records = []; TIMES.times { records << BenchRecord.create.reload }
30+
Benchmark.ips do |x|
31+
x.config(:suite => BenchTestHelper::Suite::INSTANCE)
3132

32-
Benchmark.bmbm do |x|
33-
34-
x.report("BenchRecord#update() [#{TIMES}x]") do
35-
TIMES.times do |i|
36-
records[i].update empty
37-
end
33+
record = BenchRecord.create.reload
34+
x.report("BenchRecord#update()") do
35+
record.update empty
3836
end
3937

4038
fields.each do |field, value|
4139
label = value
4240
label = "#{value[0,16]}...(#{value.size})" if value.is_a?(String) && value.size > 16
43-
attrs = Hash.new; attrs[field] = value
44-
x.report("BenchRecord#update('#{field}' => #{label.inspect}) [#{TIMES}x]") do
45-
# attrs = Hash.new; attrs[field] = value
46-
TIMES.times do |i|
47-
records[i].update(attrs)
48-
end
41+
record = BenchRecord.create.reload
42+
x.report("BenchRecord#update('#{field}' => #{label.inspect})") do
43+
record.update(field => value)
4944
end
5045
end
5146

52-
attrs = fields
53-
x.report("BenchRecord#update(...) [#{TIMES}x]") do
54-
# attrs = fields.dup
55-
TIMES.times do |i|
56-
records[i].update(attrs)
57-
end
47+
x.report("BenchRecord#update(...)") do
48+
record.update(fields)
5849
end
5950

6051
end

bench/setup.rb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: false
22

3-
require 'rubygems' unless defined? Gem
3+
require 'benchmark/ips'
44

55
if ENV['RAILS'] # Use local clone of Rails
66
rails_dir = ENV['RAILS']
@@ -120,6 +120,26 @@ def gc; GC.start end
120120

121121
end
122122

123+
class Suite # for Benchmar.ips
124+
125+
def warming(*)
126+
BenchTestHelper.gc
127+
end
128+
129+
def running(*)
130+
BenchTestHelper.gc
131+
end
132+
133+
def warmup_stats(*)
134+
end
135+
136+
def add_report(*)
137+
end
138+
139+
INSTANCE = self.new
140+
141+
end
142+
123143
end
124144

125145
def do_profile_data(&block)

0 commit comments

Comments
 (0)