Skip to content

Commit 1535d1a

Browse files
committed
[BENCHMARKING] Use Benchmark.realtime to capture total duration
1 parent 7f0df06 commit 1535d1a

File tree

3 files changed

+20
-33
lines changed

3 files changed

+20
-33
lines changed

profile/benchmarking/complex.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class Complex
3636
#
3737
# @since 7.0.0
3838
def index_documents(opts = {})
39-
duration = 0
4039
results = []
4140
slices = dataset_slices
4241

@@ -46,8 +45,8 @@ def index_documents(opts = {})
4645
end
4746
end
4847

49-
with_cleanup do
50-
duration = Benchmark.realtime do
48+
duration = with_cleanup do
49+
Benchmark.realtime do
5150
results = measured_repetitions.times.collect do
5251
Benchmark.realtime do
5352
slices.each do |slice|
@@ -75,10 +74,9 @@ def index_documents(opts = {})
7574
#
7675
# @since 7.0.0
7776
def search_documents(opts = {})
78-
duration = 0
7977
results = []
8078

81-
with_cleanup do
79+
duration = with_cleanup do
8280
slices = dataset_slices
8381
sample_slice = slices.collect do |slice|
8482
client.bulk(body: slice)
@@ -93,7 +91,7 @@ def search_documents(opts = {})
9391
client.search(request)
9492
end
9593

96-
duration = Benchmark.realtime do
94+
Benchmark.realtime do
9795
results = measured_repetitions.times.collect do
9896
Benchmark.realtime do
9997
client.search(request)

profile/benchmarking/measurable.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,6 @@ def result_cluster_client
282282
Elasticsearch::Client.new(opts)
283283
end
284284
end
285-
286-
def current_time
287-
# Use monotonic time to provide problems with leap seconds, time changes, syncs etc.
288-
Process.clock_gettime(Process::CLOCK_MONOTONIC)
289-
end
290285
end
291286
end
292287
end

profile/benchmarking/simple.rb

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,15 @@ def ping(opts = {})
7070
#
7171
# @since 7.0.0
7272
def create_index(opts = {})
73-
duration = 0
7473
results = []
7574
action_iterations = 10
7675

7776
warmup_repetitions.times do
7877
client.indices.create(index: "benchmarking-#{Time.now.to_f}")
7978
end
8079

81-
with_cleanup do
82-
duration = Benchmark.realtime do
80+
duration = with_cleanup do
81+
Benchmark.realtime do
8382
results = measured_repetitions.times.collect do |i|
8483
index_names = action_iterations.times.collect { |j| (measured_repetitions*i) + j }
8584
Benchmark.realtime do
@@ -108,7 +107,6 @@ def create_index(opts = {})
108107
#
109108
# @since 7.0.0
110109
def index_document_small(opts={})
111-
duration = 0
112110
results = []
113111
document = small_document
114112
action_iterations = 10
@@ -117,8 +115,8 @@ def index_document_small(opts={})
117115
client.create(index: INDEX, body: document)
118116
end
119117

120-
with_cleanup do
121-
duration = Benchmark.realtime do
118+
duration = with_cleanup do
119+
Benchmark.realtime do
122120
results = measured_repetitions.times.collect do
123121
Benchmark.realtime do
124122
action_iterations.times do
@@ -149,7 +147,6 @@ def index_document_small(opts={})
149147
#
150148
# @since 7.0.0
151149
def index_document_large(opts={})
152-
duration = 0
153150
results = []
154151
document = large_document
155152
action_iterations = 1_000
@@ -158,8 +155,8 @@ def index_document_large(opts={})
158155
client.create(index: INDEX, body: document)
159156
end
160157

161-
with_cleanup do
162-
duration = Benchmark.realtime do
158+
duration = with_cleanup do
159+
Benchmark.realtime do
163160
results = measured_repetitions.times.collect do
164161
Benchmark.realtime do
165162
action_iterations.times do
@@ -190,17 +187,16 @@ def index_document_large(opts={})
190187
#
191188
# @since 7.0.0
192189
def get_document_small(opts={})
193-
duration = 0
194190
results = []
195191
action_iterations = 1_000
196192

197-
with_cleanup do
193+
duration = with_cleanup do
198194
id = client.create(index: INDEX, body: small_document)['_id']
199195
warmup_repetitions.times do
200196
client.get(index: INDEX, id: id)
201197
end
202198

203-
duration = Benchmark.realtime do
199+
Benchmark.realtime do
204200
results = measured_repetitions.times.collect do
205201
Benchmark.realtime do
206202
action_iterations.times do
@@ -235,13 +231,13 @@ def get_document_large(opts={})
235231
results = []
236232
action_iterations = 1_000
237233

238-
with_cleanup do
234+
duration = with_cleanup do
239235
id = client.create(index: INDEX, body: large_document)['_id']
240236
warmup_repetitions.times do
241237
client.get(index: INDEX, id: id)
242238
end
243239

244-
duration = Benchmark.realtime do
240+
Benchmark.realtime do
245241
results = measured_repetitions.times.collect do
246242
Benchmark.realtime do
247243
action_iterations.times do
@@ -276,7 +272,7 @@ def search_document_small(opts={})
276272
results = []
277273
action_iterations = 1_000
278274

279-
with_cleanup do
275+
duration = with_cleanup do
280276
client.create(index: INDEX, body: small_document)
281277
search_criteria = { match: { cuisine: 'mexican' } }
282278
request = { body: { query: search_criteria } }
@@ -290,7 +286,7 @@ def search_document_small(opts={})
290286
client.search(request)
291287
end
292288

293-
duration = Benchmark.realtime do
289+
Benchmark.realtime do
294290
results = measured_repetitions.times.collect do
295291
Benchmark.realtime do
296292
action_iterations.times do
@@ -321,11 +317,10 @@ def search_document_small(opts={})
321317
#
322318
# @since 7.0.0
323319
def search_document_large(opts={})
324-
duration = 0
325320
results = []
326321
action_iterations = 1_000
327322

328-
with_cleanup do
323+
duration = with_cleanup do
329324
client.create(index: INDEX, body: large_document)
330325
search_criteria = { match: { 'user.lang': 'en' } }
331326
request = { body: { query: search_criteria } }
@@ -338,7 +333,7 @@ def search_document_large(opts={})
338333
client.search(request)
339334
end
340335

341-
duration = Benchmark.realtime do
336+
Benchmark.realtime do
342337
results = measured_repetitions.times.collect do
343338
Benchmark.realtime do
344339
action_iterations.times do
@@ -369,11 +364,10 @@ def search_document_large(opts={})
369364
#
370365
# @since 7.0.0
371366
def update_document(opts={})
372-
duration = 0
373367
results = []
374368
action_iterations = 1_000
375369

376-
with_cleanup do
370+
duration = with_cleanup do
377371
document = small_document
378372
id = client.create(index: INDEX, body: document)['_id']
379373
field = document.find { |k,v| k != 'id' && v.is_a?(String) }.first
@@ -384,7 +378,7 @@ def update_document(opts={})
384378
body: { doc: { field: "#{document[field]}-#{i}" } })
385379
end
386380

387-
duration = Benchmark.realtime do
381+
Benchmark.realtime do
388382
results = measured_repetitions.times.collect do
389383
Benchmark.realtime do
390384
action_iterations.times do |i|

0 commit comments

Comments
 (0)