@@ -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