@@ -38,24 +38,22 @@ class Simple
3838 #
3939 # @since 7.0.0
4040 def ping ( opts = { } )
41- start = 0
42- end_time = 0
4341 results = [ ]
4442 action_iterations = 1_000
4543
4644 warmup_repetitions . times { client . ping }
4745
48- start = current_time
49- results = measured_repetitions . times . collect do
50- Benchmark . realtime do
51- action_iterations . times do
52- client . ping
46+ duration = Benchmark . realtime do
47+ results = measured_repetitions . times . collect do
48+ Benchmark . realtime do
49+ action_iterations . times do
50+ client . ping
51+ end
5352 end
5453 end
5554 end
56- end_time = current_time
5755
58- options = { duration : end_time - start ,
56+ options = { duration : duration ,
5957 operation : __method__ ,
6058 action_iterations : action_iterations }
6159 index_results! ( results , options )
@@ -72,8 +70,7 @@ def ping(opts = {})
7270 #
7371 # @since 7.0.0
7472 def create_index ( opts = { } )
75- start = 0
76- end_time = 0
73+ duration = 0
7774 results = [ ]
7875 action_iterations = 10
7976
@@ -82,19 +79,19 @@ def create_index(opts = {})
8279 end
8380
8481 with_cleanup do
85- start = current_time
86- results = measured_repetitions . times . collect do |i |
87- index_names = action_iterations . times . collect { |j | ( measured_repetitions *i ) + j }
88- Benchmark . realtime do
89- action_iterations . times do |j |
90- client . indices . create ( index : "benchmarking-#{ index_names [ j ] } " )
82+ duration = Benchmark . realtime do
83+ results = measured_repetitions . times . collect do |i |
84+ index_names = action_iterations . times . collect { |j | ( measured_repetitions *i ) + j }
85+ Benchmark . realtime do
86+ action_iterations . times do |j |
87+ client . indices . create ( index : "benchmarking-#{ index_names [ j ] } " )
88+ end
9189 end
9290 end
9391 end
94- end_time = current_time
9592 end
9693
97- options = { duration : end_time - start ,
94+ options = { duration : duration ,
9895 operation : __method__ ,
9996 action_iterations : action_iterations }
10097 index_results! ( results , options )
@@ -111,8 +108,7 @@ def create_index(opts = {})
111108 #
112109 # @since 7.0.0
113110 def index_document_small ( opts = { } )
114- start = 0
115- end_time = 0
111+ duration = 0
116112 results = [ ]
117113 document = small_document
118114 action_iterations = 10
@@ -122,18 +118,18 @@ def index_document_small(opts={})
122118 end
123119
124120 with_cleanup do
125- start = current_time
126- results = measured_repetitions . times . collect do
127- Benchmark . realtime do
128- action_iterations . times do
129- client . create ( index : INDEX , body : document )
121+ duration = Benchmark . realtime do
122+ results = measured_repetitions . times . collect do
123+ Benchmark . realtime do
124+ action_iterations . times do
125+ client . create ( index : INDEX , body : document )
126+ end
130127 end
131128 end
132129 end
133- end_time = current_time
134130 end
135131
136- options = { duration : end_time - start ,
132+ options = { duration : duration ,
137133 operation : __method__ ,
138134 dataset : 'small_document' ,
139135 dataset_size : ObjectSpace . memsize_of ( small_document ) ,
@@ -153,8 +149,7 @@ def index_document_small(opts={})
153149 #
154150 # @since 7.0.0
155151 def index_document_large ( opts = { } )
156- start = 0
157- end_time = 0
152+ duration = 0
158153 results = [ ]
159154 document = large_document
160155 action_iterations = 1_000
@@ -164,18 +159,18 @@ def index_document_large(opts={})
164159 end
165160
166161 with_cleanup do
167- start = current_time
168- results = measured_repetitions . times . collect do
169- Benchmark . realtime do
170- action_iterations . times do
171- client . create ( index : INDEX , body : document )
162+ duration = Benchmark . realtime do
163+ results = measured_repetitions . times . collect do
164+ Benchmark . realtime do
165+ action_iterations . times do
166+ client . create ( index : INDEX , body : document )
167+ end
172168 end
173169 end
174170 end
175- end_time = current_time
176171 end
177172
178- options = { duration : end_time - start ,
173+ options = { duration : duration ,
179174 operation : __method__ ,
180175 dataset : 'large_document' ,
181176 dataset_size : ObjectSpace . memsize_of ( large_document ) ,
@@ -195,8 +190,7 @@ def index_document_large(opts={})
195190 #
196191 # @since 7.0.0
197192 def get_document_small ( opts = { } )
198- start = 0
199- end_time = 0
193+ duration = 0
200194 results = [ ]
201195 action_iterations = 1_000
202196
@@ -206,18 +200,18 @@ def get_document_small(opts={})
206200 client . get ( index : INDEX , id : id )
207201 end
208202
209- start = current_time
210- results = measured_repetitions . times . collect do
211- Benchmark . realtime do
212- action_iterations . times do
213- client . get ( index : INDEX , id : id )
203+ duration = Benchmark . realtime do
204+ results = measured_repetitions . times . collect do
205+ Benchmark . realtime do
206+ action_iterations . times do
207+ client . get ( index : INDEX , id : id )
208+ end
214209 end
215210 end
216211 end
217- end_time = current_time
218212 end
219213
220- options = { duration : end_time - start ,
214+ options = { duration : duration ,
221215 operation : __method__ ,
222216 dataset : 'small_document' ,
223217 dataset_size : ObjectSpace . memsize_of ( small_document ) ,
@@ -237,8 +231,7 @@ def get_document_small(opts={})
237231 #
238232 # @since 7.0.0
239233 def get_document_large ( opts = { } )
240- start = 0
241- end_time = 0
234+ duration = 0
242235 results = [ ]
243236 action_iterations = 1_000
244237
@@ -248,18 +241,18 @@ def get_document_large(opts={})
248241 client . get ( index : INDEX , id : id )
249242 end
250243
251- start = current_time
252- results = measured_repetitions . times . collect do
253- Benchmark . realtime do
254- action_iterations . times do
255- client . get ( index : INDEX , id : id )
244+ duration = Benchmark . realtime do
245+ results = measured_repetitions . times . collect do
246+ Benchmark . realtime do
247+ action_iterations . times do
248+ client . get ( index : INDEX , id : id )
249+ end
256250 end
257251 end
258252 end
259- end_time = current_time
260253 end
261254
262- options = { duration : end_time - start ,
255+ options = { duration : duration ,
263256 operation : __method__ ,
264257 dataset : 'large_document' ,
265258 dataset_size : ObjectSpace . memsize_of ( large_document ) ,
@@ -279,8 +272,7 @@ def get_document_large(opts={})
279272 #
280273 # @since 7.0.0
281274 def search_document_small ( opts = { } )
282- start = 0
283- end_time = 0
275+ duration = 0
284276 results = [ ]
285277 action_iterations = 1_000
286278
@@ -298,18 +290,18 @@ def search_document_small(opts={})
298290 client . search ( request )
299291 end
300292
301- start = current_time
302- results = measured_repetitions . times . collect do
303- Benchmark . realtime do
304- action_iterations . times do
305- client . search ( request )
293+ duration = Benchmark . realtime do
294+ results = measured_repetitions . times . collect do
295+ Benchmark . realtime do
296+ action_iterations . times do
297+ client . search ( request )
298+ end
306299 end
307300 end
308301 end
309- end_time = current_time
310302 end
311303
312- options = { duration : end_time - start ,
304+ options = { duration : duration ,
313305 operation : __method__ ,
314306 dataset : 'small_document' ,
315307 dataset_size : ObjectSpace . memsize_of ( small_document ) ,
@@ -329,8 +321,7 @@ def search_document_small(opts={})
329321 #
330322 # @since 7.0.0
331323 def search_document_large ( opts = { } )
332- start = 0
333- end_time = 0
324+ duration = 0
334325 results = [ ]
335326 action_iterations = 1_000
336327
@@ -347,18 +338,18 @@ def search_document_large(opts={})
347338 client . search ( request )
348339 end
349340
350- start = current_time
351- results = measured_repetitions . times . collect do
352- Benchmark . realtime do
353- action_iterations . times do
354- client . search ( request )
341+ duration = Benchmark . realtime do
342+ results = measured_repetitions . times . collect do
343+ Benchmark . realtime do
344+ action_iterations . times do
345+ client . search ( request )
346+ end
355347 end
356348 end
357349 end
358- end_time = current_time
359350 end
360351
361- options = { duration : end_time - start ,
352+ options = { duration : duration ,
362353 operation : __method__ ,
363354 dataset : 'large_document' ,
364355 dataset_size : ObjectSpace . memsize_of ( large_document ) ,
@@ -378,8 +369,7 @@ def search_document_large(opts={})
378369 #
379370 # @since 7.0.0
380371 def update_document ( opts = { } )
381- start = 0
382- end_time = 0
372+ duration = 0
383373 results = [ ]
384374 action_iterations = 1_000
385375
@@ -394,20 +384,20 @@ def update_document(opts={})
394384 body : { doc : { field : "#{ document [ field ] } -#{ i } " } } )
395385 end
396386
397- start = current_time
398- results = measured_repetitions . times . collect do
399- Benchmark . realtime do
400- action_iterations . times do |i |
401- client . update ( index : INDEX ,
402- id : id ,
403- body : { doc : { field : "#{ document [ field ] } -#{ i } " } } )
387+ duration = Benchmark . realtime do
388+ results = measured_repetitions . times . collect do
389+ Benchmark . realtime do
390+ action_iterations . times do |i |
391+ client . update ( index : INDEX ,
392+ id : id ,
393+ body : { doc : { field : "#{ document [ field ] } -#{ i } " } } )
394+ end
404395 end
405396 end
406397 end
407- end_time = current_time
408398 end
409399
410- options = { duration : end_time - start ,
400+ options = { duration : duration ,
411401 operation : __method__ ,
412402 dataset : 'small_document' ,
413403 dataset_size : ObjectSpace . memsize_of ( small_document ) ,
0 commit comments