Skip to content

Commit

Permalink
Extract details of time measurement to common method
Browse files Browse the repository at this point in the history
  • Loading branch information
PragTob authored and estolfo committed Apr 12, 2019
1 parent e350557 commit dbd5863
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
8 changes: 4 additions & 4 deletions profile/benchmarking/complex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ def index_documents(opts = {})
end

with_cleanup do
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
start = current_time
results = measured_repetitions.times.collect do
Benchmark.realtime do
slices.each do |slice|
client.bulk(body: slice)
end
end
end
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
end_time = current_time
results
end

Expand Down Expand Up @@ -96,13 +96,13 @@ def search_documents(opts = {})
client.search(request)
end

start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
start = current_time
results = measured_repetitions.times.collect do
Benchmark.realtime do
client.search(request)
end
end
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
end_time = current_time
results
end

Expand Down
5 changes: 5 additions & 0 deletions profile/benchmarking/measurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,11 @@ def result_cluster_client
Elasticsearch::Client.new(opts)
end
end

def current_time
# Use monotonic time to provide problems with leap seconds, time changes, syncs etc.
Process.clock_gettime(Process::CLOCK_MONOTONIC)
end
end
end
end
36 changes: 18 additions & 18 deletions profile/benchmarking/simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ def ping(opts = {})

warmup_repetitions.times { client.ping }

start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
start = current_time
results = measured_repetitions.times.collect do
Benchmark.realtime do
action_iterations.times do
client.ping
end
end
end
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
end_time = current_time

options = { duration: end_time - start,
operation: __method__,
Expand Down Expand Up @@ -82,15 +82,15 @@ def create_index(opts = {})
end

with_cleanup do
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
start = current_time
results = measured_repetitions.times.collect do
Benchmark.realtime do
action_iterations.times do
client.indices.create(index: "benchmarking-#{Time.now.to_f}")
end
end
end
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
end_time = current_time
results
end

Expand Down Expand Up @@ -122,15 +122,15 @@ def index_document_small(opts={})
end

with_cleanup do
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
start = current_time
results = measured_repetitions.times.collect do
Benchmark.realtime do
action_iterations.times do
client.create(index: INDEX, body: document)
end
end
end
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
end_time = current_time
results
end

Expand Down Expand Up @@ -165,15 +165,15 @@ def index_document_large(opts={})
end

with_cleanup do
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
start = current_time
results = measured_repetitions.times.collect do
Benchmark.realtime do
action_iterations.times do
client.create(index: INDEX, body: document)
end
end
end
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
end_time = current_time
results
end

Expand Down Expand Up @@ -208,15 +208,15 @@ def get_document_small(opts={})
client.get(index: INDEX, id: id)
end

start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
start = current_time
results = measured_repetitions.times.collect do
Benchmark.realtime do
action_iterations.times do
client.get(index: INDEX, id: id)
end
end
end
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
end_time = current_time
results
end

Expand Down Expand Up @@ -251,15 +251,15 @@ def get_document_large(opts={})
client.get(index: INDEX, id: id)
end

start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
start = current_time
results = measured_repetitions.times.collect do
Benchmark.realtime do
action_iterations.times do
client.get(index: INDEX, id: id)
end
end
end
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
end_time = current_time
end

options = { duration: end_time - start,
Expand Down Expand Up @@ -301,15 +301,15 @@ def search_document_small(opts={})
client.search(request)
end

start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
start = current_time
results = measured_repetitions.times.collect do
Benchmark.realtime do
action_iterations.times do
client.search(request)
end
end
end
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
end_time = current_time
end

options = { duration: end_time - start,
Expand Down Expand Up @@ -350,15 +350,15 @@ def search_document_large(opts={})
client.search(request)
end

start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
start = current_time
results = measured_repetitions.times.collect do
Benchmark.realtime do
action_iterations.times do
client.search(request)
end
end
end
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
end_time = current_time
results
end

Expand Down Expand Up @@ -398,7 +398,7 @@ def update_document(opts={})
body: { doc: { field: "#{document[field]}-#{i}" } })
end

start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
start = current_time
results = measured_repetitions.times.collect do
Benchmark.realtime do
action_iterations.times do |i|
Expand All @@ -408,7 +408,7 @@ def update_document(opts={})
end
end
end
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
end_time = current_time
results
end

Expand Down

0 comments on commit dbd5863

Please sign in to comment.