Skip to content

Instantly share code, notes, and snippets.

@lucivaldo
Created January 18, 2024 21:50
Show Gist options
  • Save lucivaldo/e7e7e7a55e15200709e70dd4b874fbae to your computer and use it in GitHub Desktop.
Save lucivaldo/e7e7e7a55e15200709e70dd4b874fbae to your computer and use it in GitHub Desktop.
Classe Ruby para medir o tempo de execução de um código passado como bloco de código
class ElapsedTime
def elapsed
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
yield if block_given?
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
elapsed_time = "%.2f" % (end_time - start_time)
puts "Tempo decorrido: #{elapsed_time} segundos"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment