I
I
Iqbol2016-01-27 19:20:13
ruby
Iqbol, 2016-01-27 19:20:13

How to calculate the execution time of a loop?

Greetings.
How can I calculate the execution time of each loop using Ruby.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
Helsus, 2016-01-27
@Helsus

In Stdlib: ruby-doc.org/stdlib-2.0.0/libdoc/benchmark/rdoc/Be...

A
Alexander Pavlenko, 2016-01-27
@RichyNix

The easiest way is to create a variable before the loop into which to write the current time, and create a variable after the loop into which to write the time.
We apply the arithmetic operation time2 - time1 and get the output of the loop execution time

V
Vladislav Kopylov, 2016-04-14
@kopylov_vlad

begin_time = Time.now
10.times do
  sleep(1)
end
puts Time.now - begin_time

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question